473,508 Members | 2,412 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.executeQuery("select * from image_table");
while(rs.next())
{
byte barray[] = rs.getBytes(4);
String get_price=rs.getString(5);
response.setContentType("image/gif");
response.getOutputStream().write(barray);
out.println("Price in Rs. "+get_price);
}
response.getOutputStream().flush();
response.getOutputStream().close();

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 33295
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.executeQuery("select * from image_table");
while(rs.next())
{
byte barray[] = rs.getBytes(4);
String get_price=rs.getString(5);
response.setContentType("image/gif");
response.getOutputStream().write(barray);
out.println("Price in Rs. "+get_price);
}
response.getOutputStream().flush();
response.getOutputStream().close();

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,Please 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.getString(1));
String file_extension=rs.getString(3);
barray = rs.getBytes(4);
list.add(file_extension);
fileoutputstream = new FileOutputStream(file_extension);

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.getString(1));
String file_extension=rs.getString(3);
barray = rs.getBytes(4);
list.add(file_extension);
fileoutputstream = new FileOutputStream(file_extension);

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
2373
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...
0
1317
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...
5
5016
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...
4
2629
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...
5
1864
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...
2
6806
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...
2
2781
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...
1
2034
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...
1
3009
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...
0
7115
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...
0
7321
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,...
0
7377
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...
1
7036
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...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4705
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...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.