• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

how to convert byte[] to blob

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

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


//myByte is my byte array

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


----------------------------------
 
Sheriff
Posts: 27235
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 4323
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 4323
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Blob blob=null; //is our blob object
byte[] buffer; //is our byte array
blob=new SerialBlob(buffer);
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The SerialBlob is a very good option on this
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Blob blob = Hibernate.createBlob(bytes);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic