I want to save an image in an Oracle DB as a BLOB.
When trying to do this, I get this error message
java.sql.SQLException: ORA-01465: invalid hex number
My code snippet:
...
Blob blob = con.createBlob();
blob.setBytes(1, myByteArray); // blob = oracle.sql.BLOB@7543e69b
String query = "update pictures set pic = \'" + blob + "\' where txt = \'Photo1\'";
statement.executeQuery(query);
...
Next I tried a new version, in which I only inserted the hex number(7543e69b) behind "oracle.sql.BLOB@" in the DB.
That worked, and after reading out the blob I have a blob object again.
But after convert this blob object to icon, can no longer display an image. But after converting from blob to icon, the image is no longer displayed in the GUI. And when debugging, the size of the image is, for example, width: -1, height: -1, ....
This code snippet:
...
Blob blob = con.createBlob();
blob.setBytes(1, myByteArray); // blob = oracle.sql.BLOB@7543e69b
String picture = blob + "";
picture = picture.substring(16); // picture = 7543e69b
String query = "update pictures set pic = \'" + picture + "\' where txt = \'Photo1\'";
statement.executeQuery(query);
...
Blob a = rs.getBlob(4);
ImageIcon imageIcon = null;
try {
byte[] bArray = a.getBytes((long) 1, (int) a.length());
imageIcon = new ImageIcon(bArray);
} catch (Exception ex) {
...
}
photo.setIcon(imageIcon);
What is going wrong here? Is the saving wrong?