Need to display multiple images from database on a webpage.

Reply

Join Date: May 2009
Posts: 2
Reputation: raghuprasad is an unknown quantity at this point 
Solved Threads: 0
raghuprasad raghuprasad is offline Offline
Newbie Poster

Need to display multiple images from database on a webpage.

 
0
  #1
May 11th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,605
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 460
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Need to display multiple images from database on a webpage.

 
0
  #2
May 11th, 2009
Originally Posted by raghuprasad View Post
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.

  1. ...
  2. int f=1;
  3. String tempfolder="/tmp/";
  4. String filename="";
  5. while(rs1.next()){
  6. int len = imgLen.length();
  7. byte [] rb = new byte[len];
  8. InputStream readImg = rs1.getBinaryStream(1);
  9. int index=readImg.read(rb, 0, len);
  10. filename=tempfolder + "A" + f;
  11. FileOutputStream os=new FileOutputStream(filename);
  12. os.write(rb);
  13. os.close();
  14. out.println("<img src='" + filename + "' />");
  15. f++;
  16. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC