title: Image is not displayed from Oracle table using servlet
body: <p>After a long trial ,I finally successfully able to upload an <strong>image</strong> to an <code>oracle database</code>. At least my code says so. However to check whether the image has been successfully I wrote a <code>servlet</code>. After running the <code>servlet</code> I get a black screen in my browser and nothing else. The <code>servlet</code> code is:</p>
  
  <pre><code>import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.sql.Blob;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class DisplayImage extends HttpServlet {
  private static final long serialVersionUID = 1L;
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException  {
      // TODO Auto-generated method stub
       try {
           Class.forName("oracle.jdbc.driver.OracleDriver");  
           String url = "jdbc:oracle:thin:@localhost:1521:XE";
           Connection con = DriverManager.getConnection(url,"system","root");
              PreparedStatement ps = con.prepareStatement("select image from insertimage");
              ResultSet rs = ps.executeQuery();
              rs.next();
              Blob  b = rs.getBlob("image");
              response.setContentType("image/jpeg");
              response.setContentLength( (int) b.length());
              InputStream is = b.getBinaryStream();
              OutputStream os = response.getOutputStream();
              byte buf[] = new byte[(int) b.length()];
              is.read(buf);
              os.write(buf);
              os.close();
          }
          catch(Exception ex) {
               System.out.println(ex.getMessage());
          }
      } 
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          processRequest(request, response);
      } 
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          processRequest(request, response);
  }
  
    }
  </code></pre>
  
  <p>By the way, as I am totally new to this, I took extensive help from this <a href="http://www.srikanthtechnologies.com/blog/java/fileupload.aspx" rel="nofollow">File upload and display demo</a>.
  <strong>EDIT :</strong> I get the black screen if only viewed from FF , but if viewed from internal web browser of Eclipse it shows me a single word <code>upload</code> . Very strange behaviour!!</p>