var BUFSIZE = 8192; // You can allocate a Java byte array like this var buf = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, BUFSIZE); var os = new java.io.ByteArrayOutputStream(); var count; while ((count = result.read(buf, 0, buf.length)) > 0) { os.write(buf, 0, count); } os.flush(); var image = os.toByteArray();
Joern Wallstabe wrote:
On Tue, 09 Dec 2003 14:56:20 +0100 Christian Haul <[EMAIL PROTECTED]> wrote:
Joern Wallstabe wrote:
or can I use convert, setColumn etc. from org.apache.cocoon.util.JDBCTypeConversions ??Guess so. But the input object must be of a supported type (the sample uses the raw-request-param module for this).
Chris.
Hello Chris, thanks for the quick reply. To get the image into the database i'm using the following
importPackage(Packages.org.apache.cocoon.util);
if (my_image != null) { var ps=conn.prepareStatement("UPDATE my_table SET image=? WHERE image_id=?");
ps.setString(2,imageID); ps.setBinaryStream(1,my_image,my_image_size);
ps.executeUpdate();
ps.close();
}
To get the image out:
....
importPackage(Packages.org.apache.cocoon.util);
var ps=conn.prepareStatement("SELECT image FROM my_table WHERE image_id=?");
ps.setString(1,imageID);
var rs= ps.executeQuery();
if (rs!= null){
if(rs.next()){
var result = rs.getBinaryStream(1);
}
rs.close();
}
ps.close();
....
How to I have to process the resulting bytearray (var result = rs.getBinaryStream(1);) to get an image back ?
Regards jörn
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]