468,296 Members | 1,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

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.
Expand|Select|Wrap|Line Numbers
  1.   <% 
  2.         byte[] imgData = null ;
  3.         Class.forName("com.mysql.jdbc.Driver");
  4.         Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rich","root","");
  5.          Statement stmt = con.createStatement();
  6.           String id = request.getParameter("id"); 
  7.  String name= request.getParameter("name"); 
  8.   String city= request.getParameter("city"); 
  9.    String state = request.getParameter("state"); 
  10.  ResultSet resultset =stmt.executeQuery("select * from publishers where id = '" + id + "' ") ; 
  11.   while(resultset.next())  
  12.   {
  13.       out.println("id:"+id);
  14. out.println("name:"+name);
  15. out.println("city"+city);
  16. out.println("state"+state);
  17.  
  18.       Blob bl = resultset.getBlob(5);
  19. byte[] pict = bl.getBytes(1,(int)bl.length());
  20. response.setContentType("image/jpg");
  21. OutputStream o = response.getOutputStream();
  22. o.write(pict);
  23. o.flush();
  24. o.close();
  25.              }
  26.  
  27.  
  28.  
  29.  
  30.  
  31.         %>
Feb 4 '13 #1
1 5935
Rabbit
12,512 Expert Mod 8TB
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.
Feb 4 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Robert | last post: by
2 posts views Thread by ameshkin | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.