Jump to Real's How-to Main page

Retrieve an Image

// column is column index in ResultSet containing the image, 
// we assume that the type is LONGVARBINARY
Image myImage = null;
InputStream stream = rset.getBinaryStream(column); 
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
  int a1 = stream.read();
  while (a1 >= 0) {
    output.write((char)a1);
     a1 = stream.read();
     }
  myImage = 
    Toolkit.getDefaultToolkit().createImage(output.toByteArray());
  output.close();
  }
catch(Exception e){}

If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]