I have stored an image in a database using Blob type. Now I can fetch this image from database using the select. I want to display this image on my jsp. In Jsp i have created a table and want it to be one of the column.
I have blob data how can I convert it back to an image and display it on my jsp page.
Thanks
Here are two options:
Option 1:
This may not be the best answer, but it will do in a pinch…
You would need to use a
InputStreamReaderto read the blob out of the column, and then create aFileOutputStreamand then create the file in a ‘created’ images directory. For example if you store you image files in a directory called/pics, you could write the files out to a directory called/pics/generated.There are some drawbacks to this approach. For one you would generate a file every time the page is requested. which may work if the files will all have different names.
Option 2:
You would use an InputStreamReader to read the blob from the row that is returned from your SQL. Create an OutputStream, using a
byte[]as the stream destination. Then it’s just a matter of writing thebyte[]out to your JSP