aspose file tools*
The moose likes JDBC and the fly likes Storing and retrieving images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Storing and retrieving images" Watch "Storing and retrieving images" New topic
Author

Storing and retrieving images

Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
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
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30309
    
150

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?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ramesh Chandra
Greenhorn

Joined: Oct 20, 2005
Posts: 17
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....
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
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.


There is no emoticon for what I am feeling!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing and retrieving images