how to display multiple images and data in jsp,mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ramrajram
    New Member
    • Feb 2013
    • 1

    how to display multiple images and data in jsp,mysql

    please help me ,am using below code.It is only one image display at a time also does not display an data values.how to display multiple images and data values.
    Code:
      <% 
            byte[] imgData = null ;
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rich","root","");
             Statement stmt = con.createStatement();
              String id = request.getParameter("id"); 
     String name= request.getParameter("name"); 
      String city= request.getParameter("city"); 
       String state = request.getParameter("state"); 
     ResultSet resultset =stmt.executeQuery("select * from publishers where id = '" + id + "' ") ; 
      while(resultset.next())  
      {
          out.println("id:"+id);
    out.println("name:"+name);
    out.println("city"+city);
    out.println("state"+state);
    
          Blob bl = resultset.getBlob(5);
    byte[] pict = bl.getBytes(1,(int)bl.length());
    response.setContentType("image/jpg");
    OutputStream o = response.getOutputStream();
    o.write(pict);
    o.flush();
    o.close();
                 }
            
            
            
            
            
            %>
    Last edited by Rabbit; Feb 4 '13, 05:08 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Is id a unique field? That is a potential issue if it is because you will only get one row at most.

    The main cause of the issue though is that you set the content type to an image. If you want to display multiple images, you will need to send html with image elements. If you want to display data that is not image data, ie these "data values" you mentioned, you can not use the image content type.

    Comment

    Working...