• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you convert an stream in to Blob data?

 
tejas bhojak
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic