aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 19556
    
  16

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you convert an stream in to Blob data?
 
Similar Threads
How to convert an object into BLOB
vvvv urgent - Scanning and saving documents into oracle db with Twain
How to convert "java.sql.Blob" object to "java.sql.Clob" object?
byte[] to blob
need to read the blob and convert it into a file