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

How to display more image from database using JSP

selvasoft
P: 34
Hi

Please help me i want display all images from my database.
but here my code that will display only one image from database.
But i want all images, any one help me.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body bgcolor ='#F5F5F5'>
  6. <font face='Bitstream Vera Sans' color='#CD5C5C'>
  7. <form name="Form1"  >
  8. </font>
  9. <%@ page import ="java.sql.*,java.util.*,java.awt.*,java.io.*" %>
  10.  
  11. <%!
  12.  
  13. %>
  14.  
  15. <%!
  16.       String DomainName ="jdbc:oracle:thin:@192.168.251.28:1521:ss";
  17.       String UserName="sss";
  18.       String PassWord="ssss";
  19.  
  20.       private byte[] getReturnInvoiceDetails(String SId)
  21.       {
  22.  
  23.            byte[] image = new byte[300000];
  24.            try
  25.            {
  26.  
  27.                   int n=0;
  28.                   n =System.in.available();
  29.                   image = new byte[n];
  30.                  Image pic =null;
  31.                   Blob blob =null;
  32.  
  33.                   String QS =" Select shadeimg  from ShadeCardSample Where id =26";
  34.  
  35.                    Class.forName("oracle.jdbc.OracleDriver");
  36.                    Connection cn=DriverManager.getConnection(DomainName,UserName,PassWord);  
  37.                    Statement  st=cn.createStatement();
  38.                    ResultSet  rs= st.executeQuery(QS);
  39.  
  40.                    while(rs.next())
  41.                    {
  42.                      image  =rs.getBytes(1);
  43.  
  44.                    }
  45.  
  46.              }
  47.            catch(Exception e)
  48.            {
  49.                System.out.println(e);
  50.            }
  51.  
  52.         return image;
  53.       }
  54. %>
  55.  
  56. <%
  57.  
  58.     String ID =(String)request.getParameter("IMGID");
  59.  
  60.     byte[] Pic = getReturnInvoiceDetails(ID);
  61.     response.setContentType("image/gif");
  62.     OutputStream o =response.getOutputStream();
  63.     o.write(Pic);
  64.     o.flush();
  65.     o.close();
  66.     out.close();    
  67. %>
  68. </form>
  69. <body>
  70. </html>
  71.  
Mar 26 '10 #1
Share this Question
Share on Google+
4 Replies


jkmyoung
Expert 100+
P: 2,057
You probably need an Vector of arrays of bytes, eg something like:
Expand|Select|Wrap|Line Numbers
  1. Vector<byte[]> images = new Vector<byte>()
  2.  
  3. ...
  4. while(rs.next()) 
  5.    image = new byte[300000]
  6.    image = rs.getBytes(1); 
  7.    images.add(image);
  8. }
  9.  
and have your display code iterate through the vector similarly.
Mar 26 '10 #2

selvasoft
P: 34
Hi jkmyoung

Thanks for your idea. I will try that.



-selvasoft
Mar 27 '10 #3

selvasoft
P: 34
hi jkmyoung

Am try that. But i cant able to find correct solution please give me any one example.








-selvasoft
Mar 31 '10 #4

P: 1
String QS =" Select shadeimg from ShadeCardSample Where id =26";
above query display only one image and change the query
Aug 23 '13 #5

Post your reply

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