Hello,
I'm facing a strange problem when I try to insert a blob in my SQL database. I'm implementing a web application using Struts and hibernate and My SQL for the database. The application runs fine when I insert the blob (which is an image in my case). However, I'm unable to see the row in the table when I go to MySQL and do a "select" statement. All I get are a bunch of dashed lines that go on forever. I simply followed instructions given in a struts and hibernate tutorial to insert blob data and I don't get any errors when I run the application. Following are the details:
Table definition in SQL:
Images{ img_id int, AUTO_INCREMENT
....
ImagData longblob,
....
}
Code to insert blob:
// The java object that maps to the database table
1) public class Images{
....
private Blob imagData;
//the get and set methods for imagData
public Blob getImagData() {
return this.imagData;
}
public void setImagData(Blob data) {
this.imagData = data;
}
}
2) The Action that performs the insertion of blob into the database
public ActionForward execute{
...
// temp object to hold table data
Images image;
//blob to hold the image binary data
Blob imgBlob;
....
//obtains a transaction -- hibernate stuff
Transaction tx = session.beginTransaction();
//creates a blob with the image data
imgBlob = org.hibernate.Hibernate.createBlob(contentFile.getInputStream());
//sets the blob value in the object using the set method of the Images bean
image.setImagData(imgBlob);
...
//saves the data using hibernate
session.save(image);
//commits data to database using hibernate
tx.commit();
}
I'm also using myEclipse for my development and deploying on the sun web server. I don't get any compile or run time errors but the output when I do a "select" on the table is strange. Any ideas on why this is happening? Would appreciate any insightinto this strange behavior!
|