• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

byte[] to blob

 
azhar bharat
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i convert a byte array to a Blob(java.sql.Blob) object?
 
Scott Selikoff
author
Saloon Keeper
Posts: 4014
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
azhar bharat
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 34669
366
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic