I have one class written from my project which reads blob data from database and display the data stored.I m copying my code here..It may help you somehow i guess.
Code:
public static void getImage(HttpServletResponse response,String site_sketch_id) throws Exception {
java.sql.Connection conn = null;
String query = null;
Statement stmt = null;
ResultSet rs = null;
conn = LookUpUtil.getConnection(true, true);
traceLogger.info("site_sketch_id : " + site_sketch_id);
response.setContentType("text/html;charset=UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
query = "select site_sketch from sketch_info where pk_book_id ='" + site_sketch_id + "' ";
traceLogger.info("query : " + query);
try {
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
response.setHeader("Content-Disposition","attachment;filename=SiteSketchImage.jpg");//for save option
response.setContentType("application/image");
rs = stmt.executeQuery(query);
while(rs.next()){
byte[] imgData=rs.getBlob("site_sketch").getBytes(1,(int)rs.getBlob("site_sketch").length());
baos.write(imgData);
}
// the contentlength is needed for MSIE!!!
response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();
out.close();
} catch (Exception e) {
traceLogger.info("Exception " + e);
} finally {
if (stmt != null)
stmt.close();
if (rs != null)
rs.close();
if (conn != null) {
conn.close();
conn = null;
}
} //End Finally
} //End Of getImage