Hi,
I have a problem with Blobs&Entity Beans with
Orion 1.2 and DB2 7.1
I'm getting the following exception while retrieving a picture from DB into
an entity bean
Error in ejbLoad : java.lng.AbstractMethodError:
COM/ibm/db2/jdbc/app/DB2ResultSet.getBlob
....
Nested exception is:
java.lng.AbstractMethodError: COM/ibm/db2/jdbc/app/DB2ResultSet.getBlob
at PhotoBean.ejbLoad(PhotoBean.java:146)
at
Photo_EntityBeanWrapper117.loadState(Photo_EntityBeanWrapper117.java:426)
at
PhotoHome_EntityHomeWrapper198.findExistingEntity(PhotoHome_EntityHomeWrappe
r198:37)
at
PhotoHome_EntityHomeWrapper198.findByPrimaryKey(PhotoHome_EntityHomeWrapper1
98.java:232)
my entity bean contains [ id(int) + array of bytes to hold the picture]
the table [id + Blob]
my code in ejbLoad :
--------------------
Context ctx = new InitialContext();
DataSource datasource = (DataSource) ctx.lookup("jdbc/DefaultEJBDS");
conn = datasource.getConnection();
ps = conn.prepareStatement("SELECT photoImage FROM photo WHERE photoId=?");
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.next()) {
String colName = "image";
Blob blobObj = rs.getBlob(colName);
if (blobObj == null){
System.out.println("[PhotoBean|ejbLoad] Error creating Blob object -
Blob
object is null");
}else{
int imgSize = (int)blobObj.length();
// Create byte[] data array to store picture data temporarily
// before writing it to a file
image = new byte[imgSize];
// Retrieve the picture as a binary stream from the Blob object
InputStream is = blobObj.getBinaryStream();
// Store the binary stream from above into image byte[] array
is.read(image);
}
}
db2.xml schema:
---------------
<type-mapping type="java.io.Serializable" name="blob" />
In the beggining I was afraid that JDBC driver for DB2 doesn't supports
blobs
but the same code works often just after the insert of the picture in
DB(???)
How do I fix this? Any clues?
Regards
Hadi