I am getting exception while fatch image from database and display image on screen. Please help me to solve this error..
int questionid ;
Connection conn = null;
conn= new DBFunction().getconnect();
Statement stmt = conn.createStatement();
questionid=4;
try
{
conn.setAutoCommit (false);
// get the image from the database
Blob img ;
byte[] imgData = null ;
String req = "Select img From questionlist Where queid = " + questionid ;
ResultSet rset = stmt.executeQuery ( req );
while (rset.next ())
{
img = rset.getBlob("img");
imgData = img.getBytes(1,(int)img.length());
}
// display the image
response.reset();
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
}
catch (Exception e)
{
e.printStackTrace();
}
Let me know where am i wrong ?