FileDocCategorySizeDatePackage
TestLongRawServlet.javaAPI DocExample1501Wed Jul 11 11:38:34 BST 2001None

TestLongRawServlet

public class TestLongRawServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)


    ServletOutputStream out = response.getOutputStream();

    Connection conn = CacheConnection.checkOut();
    Statement  stmt = null;
    ResultSet  rslt = null;

    response.setContentType("image/gif");

    try {
      stmt = conn.createStatement();
      rslt = stmt.executeQuery("select photo from person_photo");
      if (rslt.next()) {
        byte[] buffer = new byte[32];
        int    length = 0;
        InputStream in = rslt.getBinaryStream(1);
        while ((length = in.read(buffer)) != -1) {
          out.write(buffer, 0, length);
        }
      }
      else {
        response.setContentType("text/html");
        out.println("<html><head><title>Person Photo</title></head>");
        out.println("<body><h1>No data found</h1></body></html>");
        return;
      }
      stmt.close();
      stmt = null;
    }
    catch(SQLException e) {
      System.out.println("SQLException cause: " + e.getMessage());
    }
    finally {
      if (rslt != null) 
        try { rslt.close(); } catch (SQLException ignored) {}
      if (stmt != null) 
        try { stmt.close(); } catch (SQLException ignored) {}
    }
    CacheConnection.checkIn(conn);