JDBC not working properly for HSQLDB
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   NabinRaj_Pandey
Posted On:   Thursday, October 13, 2011 01:42 AM

Hi everyone 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? Exception : Exception in thread "main" java.lang.ClassCastException: org.hsqldb.jdbc.JDBCBlobClient cannot be cast to com.mysql.jdbc.Blob //retriving function..... public Object[] getProductDetailsForEmail() { try { Connection conn = db.getConnection(); Statement smnt = conn.createStatement(); String Query =   More>>


Hi everyone 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?




Exception :

Exception in thread "main" java.lang.ClassCastException:
org.hsqldb.jdbc.JDBCBlobClient cannot be
cast to com.mysql.jdbc.Blob

//retriving function.....

public Object[] getProductDetailsForEmail() {


try {
Connection conn = db.getConnection();



Statement smnt = conn.createStatement();
String Query = "SELECT * from productdetails";
ResultSet results = smnt.executeQuery(Query);


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


// NetBeans is pointing exceptin in the line below...

Blob aBlob = (Blob) results.getBlob(10);
byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());

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


String caption = "Code=some string";
}
detail[c] = caption;

detail[c + 1] = fis;


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

c = c + 2;
}



return detail;

} catch (SQLException e) {
e.printStackTrace();
return null;
}
}







//Inserting function

public void save(ProductsDto values) throws NumberFormatException {
try {
System.out.println("Passed values" + values.getCode() + values.getName() + values.getDesc());

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;

pstmt.setString(1, values.getCode());
pstmt.setString(2, values.getName());
pstmt.setDouble(3, values.getPrice());
pstmt.setInt(4, values.getQuantity());
pstmt.setBoolean(5, values.getFeatured());
pstmt.setString(6, values.getDesc());
pstmt.setString(7, values.getImgPath());


// blob inserting part********

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




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




}




   <<Less
About | Sitemap | Contact