I have stored image files in a database. Is there any way to display that image in a web browser by querying the database?
Dieter Wimberger I would recommend you to retrieve the image via JDBC from a simple HTTP servlet.
Things you have to take care about:
- Ensure to set the correct Mime type. This has to be done
calling HttpServletResponse.setContentType(String type);
- Ensure that your RDBMS does not limit result sizes (i.e. check the manuals if you get half images, and always the same block sizes).
- Attach ?<param>=<value> to your src URL to specify the picture to be retrieved.
This param can be retrieved within your service method very simple, using:
The HTML tag for the image would then be something like follows:
(Sure you can use more params if you need to do so.)
- Use some simple or sophisticated caching algorithm to limit your systems load.