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 Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "byte[] to blob" Watch "byte[] to blob" New topic

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: 3716

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
author & internet detective

Joined: May 26, 2003
Posts: 31050

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:
subject: byte[] to blob