• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Storing and retrieving images

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

i'm doing a program where i'm storing the location of an image using browse button in my welcome page into sql-server.
Now i need to display the image present in that location onto browser either using servlets or JSP.

Any help in this regards would be appreciable

Thanks in advance
Ramesh
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ramesh,
It sounds like the database part of that is to use a Statement to get the URL (String value) of a column. Then you load the image in a Servlet and output it to the HttpServletResponse.

Which of these steps are you asking about? What do you have so far?
 
Ramesh Chandra
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
[QB]Ramesh,
It sounds like the database part of that is to use a Statement to get the URL (String value) of a column. Then you load the image in a Servlet and output it to the HttpServletResponse.

Which of these steps are you asking about? What do you have so far?

Hi Jeanne,

My problem is solved in one way i.e., to store the URL of the image in the image field of the database and retrieving that URL in the for of a string in an <img> tag for a jsp page.

Now,
I want to store the image itself into the sql-server database as it is having image datatype and then retrieving that image onto a JSP page.
Hope u got my point.
Any help for you would be appreciable

Ramesh....

 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The datatype would have to be a BLOB. I would also probably have a second field that stored the data type (GIF, JPEG, BMP, etc.)

Basically, what you want to do is load the image in Java with the Image API. Get the bytes from the image and store them in the BLOB field.

Now you can read the bytes and, based on the data type, use the Image API to reconstruct the image.

Note that this is theoretical only; I havn't actually done this to know how practical/easy this might be.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Joel McNary:
The datatype would have to be a BLOB. I would also probably have a second field that stored the data type (GIF, JPEG, BMP, etc.)

Basically, what you want to do is load the image in Java with the Image API. Get the bytes from the image and store them in the BLOB field.

Now you can read the bytes and, based on the data type, use the Image API to reconstruct the image.


If I wanted to verify that the data properly encoded an image, I would use, say, ImageIO.read (of package javax.imageio) to read the image into memory. On the other hand, I would treat it as plain binary data if I didn't need to check for that, to be more efficient. In that case how do you sniff the image type? Well, if you've got a filename, you may be trust the suffix. You can also use ImageIO's getImageReaders, which peeks at the first few bytes in the stream to determine its type, and returns an Iterator<ImageReader>. Type ImageRead has the handy method getFormatName.
 
Tomorrow is the first day of the new metric calendar. Comfort me tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic