when I try to convert Oject into blob using (Blob), getting that java.lang.ClassCastException: [B cannot be cast to java.sql.Blob error.
but when I try to convert using the following code and write as an image file, gets the image corrupted.
Blob blob = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(myObj);
byte[] yourBytes = bos.toByteArray();
//blob.setBytes(1, yourBytes );
blob = new SerialBlob(yourBytes);
} finally {
out.close();
bos.close();
}
How can I safely convert object (which is an image file saved as Blob) to Blob?
NOTE: due to requirement, I can only get as Object passing from other part.
System.out.println(obj.getClass()). Add the result of the printout to your question.