This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.
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?
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
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.