| Author |
Conversion Blob to Byte Array
|
Abiodun Adisa
Ranch Hand
Joined: Jan 17, 2002
Posts: 495
|
|
I am trying to convert a Blob into a Byte array but sometimes when i run the application I get this exception Blob may not be manipulated from creating session this is the way i am converting Blob to byte Array Is there another way to convert a java.sql.Blob into a Byte array
|
 |
Parham Emami
Greenhorn
Joined: Jul 11, 2003
Posts: 15
|
|
Hi, I've used bobs with the following piece of code. You could adapt it to what you require: public void setBlob(PreparedStatement pstmt, int index, Object obj) throws DAOException, SQLException { ByteArrayOutputStream b_out = new ByteArrayOutputStream(); try { ObjectOutputStream o_out = new ObjectOutputStream(b_out); o_out.writeObject(obj); o_out.close(); } catch (IOException e) { log.error(e); throw new DAOException(e); } byte[] b = b_out.toByteArray(); ByteArrayInputStream b_in = new ByteArrayInputStream(b); pstmt.setBinaryStream(index, b_in, b.length); } this method could be used by your insert or update method like this: setBlob(pstmt1, 2, myObject); Cheers Parham
|
 |
 |
|
|
subject: Conversion Blob to Byte Array
|
|
|