wood burning stoves 2.0*
The moose likes Struts and the fly likes Displaying images stored in the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Displaying images stored in the database" Watch "Displaying images stored in the database" New topic

Displaying images stored in the database

Mary White
Ranch Hand

Joined: Jan 27, 2003
Posts: 41
I'm saving image files (bmp, jpg, gif) in the database as binary data (I'm using SQL Server). Then, I have to retrieve this file and show the image in a JSP.
I'm using Struts 1.1, SQLServer and weblogic.
How can I do this?
Ranch Hand

Joined: Jul 24, 2002
Posts: 379
I would suggest first to get a connection to the database and in someway to get a Collection of 'binary data images'; then, applying the same pattern used to convert images from their format to binary format, but on the way back, use the <html:image> Struts tag to display it on your page.
My 2 cents.

Marco Tedone<br />SCJP1.4,SCJP5,SCBCD,SCWCD
Dave Hewitson

Joined: Jun 01, 2001
Posts: 27
I was looking for a good solution to the same problem a couple of months back.
This solution may not be the best, but It was the only one I could find at the time - performance was ok using MySQL but awful on DB2 - you'll have to see for yourself.
Anyway, I used a helper servlet to get the binary data from the DB - here's the code...

The in my jsp I have...

Hope this helps.
Mary White
Ranch Hand

Joined: Jan 27, 2003
Posts: 41
Thanks Dave, your suggestion was really good
Graham Mead
Ranch Hand

Joined: Sep 28, 2001
Posts: 57
Hi Mary
Not used it myself but you could have a butchers at the JDBC 2.0 Blob interface
Found these links
The interface seems to reduce the amount of code you need to write but it might be an alternative.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Displaying images stored in the database