aspose file tools
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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "jdbc functions not working for HSQLDB" Watch "jdbc functions not working for HSQLDB" New topic
Author

jdbc functions not working for HSQLDB

navin rajpandey
Greenhorn

Joined: Oct 12, 2011
Posts: 1
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
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2531
    
  10

Welcome to the Ranch, Navin!


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc functions not working for HSQLDB