• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Storing, retrieving, displaying images

 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm working on a project where I want to store gif or jpg images into a MySQL database using the BLOB data type. That part is easy. I got that figured out. What I need to know is how do I store and retrieve the image to and from the database using which Java data types (ImageIcon maybe)? Also, ordinarily to display an image in HTML you use the <img src="..."> tag. Its' src attribute requires a string pointing to an image file in a directory structure. But in this case, I'm not retrieving the file from a directory tree, I'm getting it straight from a database. So in the JSP page how do I display an image retrieved from a class that got the image from the database? I need to see an example of how this is done.

Please advise,

Alan
 
Sheriff
Posts: 67664
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The src attribute of your img tag will address a servlet that will read the data from the db, set the content headers as appropriate, and stream the data to the response.
 
Alan Shiers
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
The src attribute of your img tag will address a servlet that will read the data from the db, set the content headers as appropriate, and stream the data to the response.



Do you have some sample code of a servlet and sends back a response for an image? I need to see an example of how it's done.

Alan
 
Bear Bibeault
Sheriff
Posts: 67664
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Courtesy of Ben Souther.

Check out his "Simple Stream" example.
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic