This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to convert byte[] to blob

 
kalpana srinuvasan
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to know whether conversion from Byte[] to blob is possible. if so , what will be the code??
please help me
thanks in advance .
 
Karthikeyan Ramaswamy
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

try this ...............


//myByte is my byte array

java.sql.Blob blob=null;
blob.setBytes(1, myByte );


----------------------------------
 
Paul Clapham
Sheriff
Pie
Posts: 20188
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully there would in real life be something else between those two lines of code. As written, the second line will throw a NullPointerException.
 
kalpana srinuvasan
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi karthikeyan... thanks for your reply...
but i have to display that bolb image in the jsp page using struts ... can you help me for that .. please
 
Scott Selikoff
author
Saloon Keeper
Posts: 3897
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Displaying a blob via struts is a lot different than converting it. You may be trying to do too many things at once. In particular, try converting the blob to a readable image, then work on serving the image via struts.
[ July 10, 2008: Message edited by: Scott Selikoff ]
 
kalpana srinuvasan
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
by using jsp , i can able to get the image as the byte[] using Formfile , i have to insert that image to my database (having the column datatype as "BLOB") and have to display in the jsp page after finished uploading ..
if you have solution for these issue . please reply..
 
Scott Selikoff
author
Saloon Keeper
Posts: 3897
16
Eclipse IDE Flex Google Web Toolkit
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you should try the struts forum. It sounds like you're not sure how to pass the data back/forth in struts. If you can save it to a database, reading it should be trivial (the JDBC component of it anyway).
[ July 10, 2008: Message edited by: Scott Selikoff ]
 
prakash jape
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blob blob=null; //is our blob object
byte[] buffer; //is our byte array
blob=new SerialBlob(buffer);
 
Vamsi Chada
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SerialBlob is a very good option on this
 
Ravi Choudhari
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
InputStream is = myBlob.getBinaryStream();

// IOUtils is from Apache Commons IO
byte[] a = IOUtils.toByteArray(is);
 
Ravi Choudhari
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blob blob = Hibernate.createBlob(bytes);
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic