This week's book giveaway is in the Design and Architecture forum.
We're giving away four copies of Communication Patterns: A Guide for Developers and Architects and have Jacqui Read on-line!
See this thread for details.
  • 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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 );


----------------------------------
 
Marshal
Posts: 28293
95
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: 4342
40
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: 4342
40
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);
 
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic