Forums Register Login

jdbc functions not working for HSQLDB

+Pie Number of slices to send: Send
I am trying to add an Image as BLOB in HSQLDB. But in the table I find something like
":hsqll:jdbc:client@f3t5h". Is anything wrong with my Java code below?

My retrieving code is like this that i usually do for other databases. Why doesn't it work for HSQLDB?

Statement stmt = conn.createStatement();

ResultSet results =stmt.executeQuery ("SELECT * from productdetails");

while (results.next()) {
String code = (String) results.getObject(1);
String name = (String) results.getObjeenter code herect(2);

String price = Double.toString((Double) results.getObject(3));
int quantity = (Integer) results.getObject(4);
Boolean featured = (Boolean) results.getObject(5);
String desc = (String) results.getObject(6);
String imgPath = (String) results.getObject(7);

// the line below is throwing class cast exception as i have mentionde below
Blob aBlob = (Blob) results.getBlob(10);
byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());

try {
FileOutputStream fis =
(FileOutputStream) getOutputStream(allBytesInBlob);

} catch (IOException ex) {
Logger.getLogger(Helper.class.getName()).log(Level.SEVERE, null, ex);
}
}

public OutputStream getOutputStream(byte[] _data) throws IOException
{
OutputStream out = new ByteArrayOutputStream();
out.write(_data);
return out;
}

This is my inserting code.

Connection conn = db.getConnection();
PreparedStatement pstmt;
String sql = "INSERT INTO PRODUCTDETAILS"
( PRODUCTCODE, NAME, PRICE, QUANTITY, FEATURED, DESCRPTION, IMAGEPATH,IMAGE )
VALUES ( ?, ?,? ,? ,? , ?, ?,?)";
pstmt = conn.prepareStatement(sql);
FileInputStream fis;


File image = new File(values.getImgPath());
fis = new FileInputStream(image);
pstmt.setBinaryStream(8, (InputStream) fis, (int) (image.length()));
pstmt.execute();

The image column is of type BLOB, obviously.
while retriving blob i am getting following error:
Exception in thread "main" java.lang.ClassCastException:
org.hsqldb.jdbc.JDBCBlobClient cannot be cast to com.mysql.jdbc.Blob
+Pie Number of slices to send: Send
Welcome to the Ranch, Navin!
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1513 times.
Similar Threads
Files
Binary Object to the database
how to store an image into the DataBase using oracle database
image storing and retriving
Reading From a Binary Large Object(BLOB)
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:08:05.