By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,806 Members | 1,380 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,806 IT Pros & Developers. It's quick & easy.

how to display multiple images and data in jsp,mysql

P: 1
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
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,422
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.