title: how to retrieve multiple blob images from mysql using jsp
body: <p>I am trying to retrieve few blob images from mysql database using java. Now , the problem is that I'm able to get only one image at a time, the other images are not getting displayed.</p>
  
  <p>Below is my jsp code , where I'm doing this(just for demonstration purpose):</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
     &lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"   %&gt;
     &lt;%@ page language="java" %&gt;
      &lt;%@ page import="java.sql.*" %&gt;
      &lt;%@ page import="java.io.*" %&gt; 
       &lt;%@ page import="java.util.*"%&gt;
  
      &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
         &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
         &lt;head&gt;
      &lt;title&gt;MindDotEditor posted Data&lt;/title&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;meta name="robots" content="noindex, nofollow" /&gt;
      &lt;link href="../sample.css" rel="stylesheet" type="text/css" /&gt;
      &lt;link rel="shortcut icon" href="../fckeditor.gif" type="image/x-icon" /&gt;
       &lt;/head&gt;
       &lt;body&gt;
  
         &lt;%
  String url = "jdbc:mysql://localhost:3306/grandsho_register";
  Connection con = null;
  Statement stmt = null;
  ResultSet rs = null;
  
  
  try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection(url,"root","root");
      stmt = con.createStatement();
      rs = stmt.executeQuery("SELECT image FROM user ");
      int i = 1;
      if(rs.next()) {
          Blob len1 = rs.getBlob("image");
          int len = (int)len1.length();
          byte[] b = new byte[len];
          InputStream readImg = rs.getBinaryStream(1);
          int index = readImg.read(b, 0, len);
          System.out.println("index" +index);
          stmt.close();
          response.reset();
          response.setContentType("image/jpg");
          response.getOutputStream().write(b,0,len);
          response.getOutputStream().flush();
      }
  } catch(Exception ex) {
      out.println(ex);
  } finally {
      rs.close();
      stmt.close();
      con.close();
  }
         %&gt;
  
      &lt;br&gt;
      &lt;center&gt;&lt;input type="button" value="Print" onclick="window.print();return false;"   /&gt;        &lt;/center&gt;
      &lt;/body&gt;
    &lt;/html&gt;    
  </code></pre>
  
  <p>Can anyone suggest how can i display multiple images on jsp page? </p>