Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes jdbc functions not working for HSQLDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc functions not working for HSQLDB" Watch "jdbc functions not working for HSQLDB" New topic

jdbc functions not working for HSQLDB

navin rajpandey

Joined: Oct 12, 2011
Posts: 2
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 ( {
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();
return out;

This is my inserting code.

Connection conn = db.getConnection();
PreparedStatement pstmt;
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()));

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
Jan Cumps

Joined: Dec 20, 2006
Posts: 2543

Welcome to the Ranch, Navin!

OCUP UML fundamental and ITIL foundation
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: jdbc functions not working for HSQLDB
jQuery in Action, 3rd edition