Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying images stored in the database

 
Mary White
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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?
Thanks
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Regards
Dave.
 
Mary White
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave, your suggestion was really good
 
Graham Mead
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mary
Not used it myself but you could have a butchers at the JDBC 2.0 Blob interface
Found these links
http://java.sun.com/j2se/1.4/docs/guide/jdbc/blob.html
http://developer.java.sun.com/developer/onlineTraining/Database/JDBC20Intro/exercises/BLOBGet/index.html
The interface seems to reduce the amount of code you need to write but it might be an alternative.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic