<Body>
<%
// Obtain the SQL statement of the image object (based on the primary key)
String showimage = "select *" +
"From table for storing images" +
"Where id = '1 '";
Bufferedinputstream inputimage = NULL;
Try {
// Conn is a connection object.
Statement ST = conn. createstatement ();
// Obtain the result set
Resultset rs1_st.exe cutequery (showimage );
// Output file name
String filename = "";
If (Rs. Next ()){
Blob blob = (BLOB) Rs. getblob ("binaryfile ");
Filename = Rs. getstring ("FILENAME ");
// Read the image bytes into the data stream
Inputimage = new bufferedinputstream (BLOB. getbinarystream ());
}
Bufferedimage image = NULL;
Image = ImageIO. Read (inputimage );
// Obtain the response output stream
Servletoutputstream so = response. getoutputstream ();
// Create an image to the page
Required imageencoder encoder = required codec. createjpegencoder (so );
Encoder. encode (image );
Inputimage. Close ();
}
%>
</Body>
<%
Catch (exception e ){
}
Finally {
Closeconn (conn );
}
%>