How to display the image from db blob data type

How to display the image from db blob data type

PreparedStatement ps = con.prepareStatement("select sixfourdata from images");

ResultSet rs = ps.executeQuery();

rs.next();

Blob b = rs.getBlob("sixfourdata");

// How to display the image from MySQL blob data type

// Note sixfourdata is a blob data type.

?

?

[361 byte] By [ElayaRajaa] at [2007-11-27 10:47:43]
# 1

You need to write a servlet. This needs to set the content type to the appropriate MIME type (according to the image format you are using).

Then open an InputStream from the Blob and copy it to the outputStream from the response with a simply buffer and loop.

This servlet is invoked from an IMG tag.

malcolmmca at 2007-7-28 22:02:37 > top of Java-index,Java Essentials,Java Programming...
# 2

Give me example code to display the image in Jsp page...

ElayaRajaa at 2007-7-28 22:02:37 > top of Java-index,Java Essentials,Java Programming...
# 3

You can't, directly. JSP will generate an HTML page. You can use it to generate an HTML page with the <IMG tag which displays the image. But the image must be retrieved by a separate transaction. The src attribute in the IMG tag must reference a servlet's URL to retrieve the image data.

JSPs are for generating HTML, anything else (like image and other formats) you need a servlet.

Sorry, but you can't get away with using JSPs for everything.>

malcolmmca at 2007-7-28 22:02:37 > top of Java-index,Java Essentials,Java Programming...
# 4

and being a bit more civilised can help as well. What ever happened to asking nicely instead of trying to boss people around?

jwentinga at 2007-7-28 22:02:37 > top of Java-index,Java Essentials,Java Programming...
# 5

Thanks for the mail.

ElayaRajaa at 2007-7-28 22:02:37 > top of Java-index,Java Essentials,Java Programming...