473,659 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to display all images in jsp from database?

30 New Member
Hi Experts,

Please Help me its very urgent.....

I stored number of images and related informations are in MS-SQL
database, datatype is "image". I want to display all the images and
related information on the jsp page.

I tried the following code, but it doesn't work properly because it
showed only one image from the database and doesn't show the price value.

ResultSet rs=st.executeQu ery("select * from image_table");
while(rs.next() )
{
byte barray[] = rs.getBytes(4);
String get_price=rs.ge tString(5);
response.setCon tentType("image/gif");
response.getOut putStream().wri te(barray);
out.println("Pr ice in Rs. "+get_price );
}
response.getOut putStream().flu sh();
response.getOut putStream().clo se();

How can I display the all images and related information in jsp?
If anybody know the solution kindly send me the coding or suggestion
to my mail-id(<removed>).

Thanks in Advance......



V. Prasath @ Arjunan.
Jun 9 '07 #1
8 33308
sumittyagi
202 Recognized Expert New Member
Hi Experts,

Please Help me its very urgent.....

I stored number of images and related informations are in MS-SQL
database, datatype is "image". I want to display all the images and
related information on the jsp page.

I tried the following code, but it doesn't work properly because it
showed only one image from the database and doesn't show the price value.

ResultSet rs=st.executeQu ery("select * from image_table");
while(rs.next() )
{
byte barray[] = rs.getBytes(4);
String get_price=rs.ge tString(5);
response.setCon tentType("image/gif");
response.getOut putStream().wri te(barray);
out.println("Pr ice in Rs. "+get_price );
}
response.getOut putStream().flu sh();
response.getOut putStream().clo se();

How can I display the all images and related information in jsp?
If anybody know the solution kindly send me the coding or suggestion
to my mail-id(<removed>).

Thanks in Advance......



V. Prasath @ Arjunan.
Hi prasath03!
Welcome to TSDN,

You have two points wrong in your code.
1. You can't send more than 1 image at a time.
2. You have to set content length in the response.

So the ideal way is to have the src of your image pointing to your image processing servlet. and send any unique id of the image with that, (as a primary key of the image.

eg:
<img src="abcServlet ?imgId=124" name="xyz">

and at servlet you will do:
Expand|Select|Wrap|Line Numbers
  1. ResultSet rs=st.executeQuery("select * from image_table where img_id=" + request.getParameter('imgId'));
  2. if(rs.next())
  3. {
  4. byte barray[] = rs.getBytes(4);
  5. String get_price=rs.getString(5);
  6. response.setContentType("image/gif");
  7. response.setContentLength(barray.length);
  8. response.getOutputStream().write(barray);
  9. out.println("Price in Rs. "+get_price);
  10. }
  11. response.getOutputStream().flush();
  12. response.getOutputStream().close();
  13.  
Jun 11 '07 #2
dmjpro
2,476 Top Contributor
You have two points wrong in your code.
1. You can't send more than 1 image at a time.
2. You have to set content length in the response.
sumittyagi,Plea se explain me these two lines in details.

Kind regards,
Dmjpro.
Jun 11 '07 #3
prasath03
30 New Member
Hi prasath03!
Welcome to TSDN,

You have two points wrong in your code.
1. You can't send more than 1 image at a time.
2. You have to set content length in the response.

So the ideal way is to have the src of your image pointing to your image processing servlet. and send any unique id of the image with that, (as a primary key of the image.

eg:
<img src="abcServlet ?imgId=124" name="xyz">

and at servlet you will do:
Expand|Select|Wrap|Line Numbers
  1. ResultSet rs=st.executeQuery("select * from image_table where img_id=" + request.getParameter('imgId'));
  2. if(rs.next())
  3. {
  4. byte barray[] = rs.getBytes(4);
  5. String get_price=rs.getString(5);
  6. response.setContentType("image/gif");
  7. response.setContentLength(barray.length);
  8. response.getOutputStream().write(barray);
  9. out.println("Price in Rs. "+get_price);
  10. }
  11. response.getOutputStream().flush();
  12. response.getOutputStream().close();
  13.  

Hi sumittyagi,

Thanks for ur reply..........

I inserted the image without id_no(primary key). Don't neglect my sql query. I need to display all images and related information without id_no. Is there any way to display the images and related information without id_no in same query? Kindly suggest me.

V. Prasath @ Arjunan.
Jun 11 '07 #4
sumittyagi
202 Recognized Expert New Member
Hi sumittyagi,

Thanks for ur reply..........

I inserted the image without id_no(primary key). Don't neglect my sql query. I need to display all images and related information without id_no. Is there any way to display the images and related information without id_no in same query? Kindly suggest me.

V. Prasath @ Arjunan.
Although there is no logic in storing images in database without any ids, even then if you want to show your images, then simply store all the image arrays in an arraylist and store that arraylist in session. also store a counter in session so that u can track how many images have been already displayed.

But don't forget to remove those images from database after all images have been displayed.

But I am again suggesting u, its not a good coding style.
Jun 11 '07 #5
prasath03
30 New Member
Although there is no logic in storing images in database without any ids, even then if you want to show your images, then simply store all the image arrays in an arraylist and store that arraylist in session. also store a counter in session so that u can track how many images have been already displayed.

But don't forget to remove those images from database after all images have been displayed.

But I am again suggesting u, its not a good coding style.

Again thanks for ur reply,

I am new in jsp. You said store the images in arraylist, but i haven't store the arraylist in session. Although i have already tried store the images in arrarylist and related information. If i want to display all the contents it displays all the contents. But only images displays like ([B@1c8f91e). Is there any way to print orginal image?
Herewith i attached my source code...

List list = new ArrayList();
while(rs.next() )
{
list.add(rs.get String(1));
String file_extension= rs.getString(3) ;
barray = rs.getBytes(4);
list.add(file_e xtension);
fileoutputstrea m = new FileOutputStrea m(file_extensio n);

for (int i = 0; i < barray.length; i++) {

list.add(barray );
} }

}

The following output is when i executed..

32.jpg
[B@1fb2ef9
111
43.jpg
[B@1c8f91e
111
images.jpg


Regards,

V. Prasath @ Arjunan.
Jun 12 '07 #6
pavi6285
2 New Member
i want to store an image in my database ACCESS.
i stored it as OLE/OBJECT.
i want to retriewve it through JSP.
if i retrieve it didnt display that image . it shows some undefined format as S@{ghdk
i dont know correctly sir...
how to set image in access and how to retrieve it from DB through jsp ..
pls help me very urgent...
give some examples...... to my mailID
Mar 11 '08 #7
pavi6285
2 New Member
i want to store an image in my database ACCESS.
i stored it as OLE/OBJECT.
i want to retriewve it through JSP.
if i retrieve it didnt display that image . it shows some undefined format as [B@1c8f91e).
i dont know correctly sir...
how to set image in access and how to retrieve it from DB through jsp ..
pls help me very urgent...
give some examples...... to my mailID
Mar 11 '08 #8
sumittyagi
202 Recognized Expert New Member
Again thanks for ur reply,

I am new in jsp. You said store the images in arraylist, but i haven't store the arraylist in session. Although i have already tried store the images in arrarylist and related information. If i want to display all the contents it displays all the contents. But only images displays like ([B@1c8f91e). Is there any way to print orginal image?
Herewith i attached my source code...

List list = new ArrayList();
while(rs.next() )
{
list.add(rs.get String(1));
String file_extension= rs.getString(3) ;
barray = rs.getBytes(4);
list.add(file_e xtension);
fileoutputstrea m = new FileOutputStrea m(file_extensio n);

for (int i = 0; i < barray.length; i++) {

list.add(barray );
} }

}

The following output is when i executed..

32.jpg
[B@1fb2ef9
111
43.jpg
[B@1c8f91e
111
images.jpg


Regards,

V. Prasath @ Arjunan.
I just forgot to tell you that images takes their own request, and each image display needs to be treated as separate request.

See this thread for a discussion on the same topic.
Mar 13 '08 #9

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

Similar topics

2
2379
by: TaeHo Yoo | last post by:
Would anyone be able to tell me how to display images dynomically from the database? I am using dataset which contains supplier name and supplier images. I can display supplier name but supplier images. Supplier image field only contains file name (ie, "a.gif"). How to bind this image to the report Thanks a lot in advance *** Sent via Developersdex http://www.developersdex.com ***
0
1324
by: Jameel | last post by:
I am facing 2 problems: 1. I have files uploaded to the server and have the relevant information in database, and now I want to pull the image name and path from database and have the images dynamically loaded into DataList, but I am not able to display images in DataList , can u help me please to sort out the problem , OR it would be better if u give me source , as u said in the above Post .
0
1752
by: Jameel | last post by:
I just happened to visit ur post: http://groups.google.co.in/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/ae471e2fdeeca01e/95061c1f95e30127?lnk=st&q=display+images+in+DataList+using+asp.net&rnum=35&hl=en#95061c1f95e30127
5
5030
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page that calls the web service to render a vertical strip of images. After doing some research I am unable to find some vb.net code that can assist in what I want to achieve. The closest thing I found was
4
2639
by: vidiot | last post by:
I am trying to create a subform that will display images related to the parent form. The subform is a continuous form as there will be several images that relate to the parent form. I checked Access help and it gave me the following code, which I have adapted for my database and it works well as a SINGLE FORM. Option Compare Database Private Sub Form_Current()
5
1869
by: GH | last post by:
Is it possible to display images on the desktop itself, like the bacground but not as a background? And not as icons either. Anything you put in the \Desktop folder shows up as an icon on the desktop, but i want to display images directly on the desktop surface. XP / VB.Net --GH
2
6832
by: Randy | last post by:
Hi, I have a small table - 2 columns, 5 rows. Col 1 is the key column and has integer values of 1 through 5. Column 2 is a varbinary(MAX) column and has jpg images loaded in it. What I want to is to bind a combobox to this table so that the combobox will display these these five images in its dropdown list and the user can then select any of them. Depending on which image is selected, the combobox will display the image and I will...
2
2794
by: pozze | last post by:
Hi, I need to display images and other record information retrieved from an SQL 2005 database in a datagrid on a web page. I'm coding in VB .net I have recently changed over from VB ASP and i'm still getting used to .net I can successfully upload images and other data into the SQL Database, I'm currently storing RecordID, File Name, Type of File (mime), File Size, and File Data. I can retreive non binary data to a datagrid but I cannot...
1
2042
by: swethak | last post by:
Hi, I write the code to display images.But it will not display image.And also gives the error like that error : Notice: Undefined index: gim in F:\Facebook\pic_up.php on line 59 plz tell that what is the problem in that code <?php
1
3018
by: harish81 | last post by:
Hi, Please help me to get images in table format. I'm new to PHP. I have written code to display images in a table format and it displays only 9 images in a single page. when i click Next Url to go to next page, by default it returns to home page. I stored images in local directory and written for each loop to display images in table format. Without using mysql as backend. My question is how to display bunch of images in table formated...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.