hi,

I am able to display a single image from the database on a webpage using the following code:

rs1 = st1.executeQuery("select image from pictures where id='5'");
  if(rs1.next()){
    int len = imgLen.length();
    byte [] rb = new byte[len];
    InputStream readImg = rs1.getBinaryStream(1);
    int index=readImg.read(rb, 0, len);  
    System.out.println("index"+index);
    st1.close();
    response.reset();
    response.setContentType("image/jpg");
    response.getOutputStream().write(rb,0,len);
    response.getOutputStream().flush();        

Can any one help me to get the code to display more than one image on a *.jsp

file. I tried putting the while loop, but it is'nt doing the job.

Thanks.

hi,

I am able to display a single image from the database on a webpage using the

following code:

rs1 = st1.executeQuery("select image from pictures where id='5'");
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
System.out.println("index"+index);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();


Can any one help me to get the code to display more than one image on a *.jsp

file. I tried putting the while loop, but it is'nt doing the job.

Thanks.

You have to save images into temp folder of your site.

...
 int f=1;
 String tempfolder="/tmp/";
 String filename="";
 while(rs1.next()){
        int len = imgLen.length();
        byte [] rb = new byte[len];
        InputStream readImg = rs1.getBinaryStream(1);
        int index=readImg.read(rb, 0, len);  
        filename=tempfolder + "A" + f;
        FileOutputStream os=new FileOutputStream(filename);
        os.write(rb);
        os.close();
        out.println("<img src='" + filename + "' />");
        f++;
 }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.