aspose file tools*
The moose likes JDBC and the fly likes byte[] to blob 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 » Databases » JDBC
Bookmark "byte[] to blob" Watch "byte[] to blob" New topic
Author

byte[] to blob

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
How do i convert a byte array to a Blob(java.sql.Blob) object?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

Check out the PreparedStatement API. In particular look at setBinaryStream(), setUnicodeStream(), and setAsciiStream() which can be used to convert a stream to a blob during an insert/update statement.


My Blog: Down Home Country Coding with Scott Selikoff
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
I am aware of other options in prepared statements api.
But, i just want to know how to convert byte[] to Blob.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Azhar,
You can create a ByteArrayInputStream from your byte[] and use that.

To create a Blob directly, you would have to write database specific code - something that should be avoided without a good reason.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: byte[] to blob
 
Similar Threads
Visual J++ Compiler and java.sql.Blob
how to send files stored as blob in mysql as attachment
Store PDF files in the database
how to convert byte[] to blob
How to upload a byte array into BLOB column?