File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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: 19785
    
  20

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?