Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes How do you convert an stream in to Blob data? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How do you convert an stream in to Blob data?" Watch "How do you convert an stream in to Blob data?" New topic
Author

How do you convert an stream in to Blob data?

tejas bhojak
Greenhorn

Joined: Oct 11, 2008
Posts: 8
We have a Blob Datatype in SQL db and the java equivalent is present in java.sql.Blob,
I basically want to convert the File in to Blob and then insert it in DB.
how do we do that??
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

If your JDBC driver is fully up-to-date, you can create a blob using Connection.createBlob(). You can then use setBinaryStream(0) to retrieve an OutputStream to which you can start writing.

If the JDBC driver does not allow you to create Blob instances this way, you can always use PreparedStatement and its setBinaryStream methods.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
 
subject: How do you convert an stream in to Blob data?