How to make a blob and save it to a mysql database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: How to make a blob and save it to a mysql database

  1. #1
    Join Date
    May 2006
    Posts
    8

    Question How to make a blob and save it to a mysql database

    I have an object and I don't know how I can cast it to a Blob, so thyat I can save it to a mysql database.

    Can Anyone help me?

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    have a look at the javadoc for blob.
    it has a method called "setBytes(long pos, byte[] bytes)".
    instantiate blob, set the data by the method and pass it to a prepared insert statement.
    that's it. by the way: there are a lot of examples reachable through http://www.google.com/search?q=jdbc+blob

  3. #3
    Join Date
    May 2006
    Posts
    8

    Question

    Thanks, but how to instantiate Blob?
    when I try
    Blob bl = new Blob();
    Eclipse underlines Blob() and says: "Cannot instantiate the type Blob, since it is not a concrete class."

    What can I do?

  4. #4
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    As denoted in the javadoc, java.sql.Blob is an interface and thus not instantiable. you will have to look out for the concrete implementation of your driver. eg if you use mysql, there should be somewhere in the package a CLASS called blob. this one you can instantiate.

  5. #5
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    You don't have to use any blob class/interface to store a pile of bytes in an SQL database. You open a byte stream using the i/o stream methods defined for the Column object, write the bytes to that stream and close it, that works for all SQL databases.
    eschew obfuscation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center