Strange,
It might work, but an image is binary data, and a String is character based. Doesn't seem logical to me to use the getString here.
anyway, here's the relevant part of my code:
 
public void getResource(OutputStream os) throws IOException{
  Connection conn = getConnection();
  PreparedStatement stmt = null;
  try{
   stmt = conn.prepareStatement("select data from resource where article_id = ? and name = ? ");
   stmt.clearParameters();
   stmt.setInt(1,articleId);
   stmt.setString(2,resourceName);
   ResultSet rs = stmt.executeQuery();
   if (rs.next()){
    InputStream in = rs.getBinaryStream(1);
    byte[] buffer = new byte[4096];
    int len = 0;
    while ((len=in.read(buffer)) != -1){
     os.write(buffer,0,len);  
    }
   }
   rs.close();
   }
  catch (SQLException e){
   System.out.println(e.getMessage());
   while ((e=e.getNextException()) != null){
    System.out.println("  next "+e.getMessage());
   }
  }
  finally {
   try{
    if (stmt != null) stmt.close();
    if (conn != null) conn.close();
   } catch (SQLException e){
    System.out.println(e.getMessage());
   }
  }
 } 
 
 
Geert Van Damme
-----Original Message-----
From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Papo Napolitano
Sent: maandag 3 december 2001 20:19
To: [EMAIL PROTECTED]
Subject: Re: BLOBs within MySQL and JSP

I just used rs.getString() to read the data from the database and for I've written a Simple Servlet to send the image to the browser.
 
Cheers,
 
Papo

Reply via email to