This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 19656
    
  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
 
Consider Paul's rocket mass heater.
 
subject: How do you convert an stream in to Blob data?
 
Similar Threads
need to read the blob and convert it into a file
vvvv urgent - Scanning and saving documents into oracle db with Twain
How to convert an object into BLOB
byte[] to blob
How to convert "java.sql.Blob" object to "java.sql.Clob" object?