Re: ejbLoad : Error retrieving a picture from DB
[Elhadi barkat] > 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); not related, but in the interest of smaller/better code :) byte[] image = blobObj.getBytes(1,blobObj.length()); I hate 1-based positioning, although I guess I can tolerate it here -- James Manning <[EMAIL PROTECTED]> GPG Key fingerprint = B913 2FBD 14A9 CE18 B2B7 9C8E A0BF B026 EEBB F6E4
ejbLoad : Error retrieving a picture from DB
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: --- 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