| | |
Need to display multiple images from database on a webpage.
![]() |
•
•
Join Date: May 2009
Posts: 2
Reputation:
Solved Threads: 0
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.
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.
Java Syntax (Toggle Plain Text)
... 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++; }
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- loading multiple images for later use (C#)
- Adding multiple images (PHP)
- Display images from database with Delete option. (PHP)
- Pulling images from database (PHP)
- Display random image from database and... (PHP)
- Display Multiple Rows From Access Database (Visual Basic 4 / 5 / 6)
- How to retrieve images from database (PHP)
- retrieving images from database in thumbnail form (PHP)
- Saving Images In Database (VB.NET)
Other Threads in the Java Forum
- Previous Thread: Saving n Retrieving Image in mysql
- Next Thread: Need help with my Java Programming
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






