Monday 19 August 2013

display the image from database

display the image from database

I have created a program in JSP to fetch the image and display it on web
page. Program is working correctly image is displayed but other contents
are not displaying. Below is the code
<%
byte[] imgData = null ;
Class.forName("com.mysql.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/buysell","root","root");
Statement stmt = con.createStatement();
ResultSet resultset =stmt.executeQuery("select * from imagemain where
id=1;") ;
while(resultset.next())
{
Blob bl = resultset.getBlob(2);
byte[] pict = bl.getBytes(1,(int)bl.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
%>
<img src="<%o.write(pict);%>" width="10" height="10">
<h1>Vishal</h1>
<%
out.print("1");
o.flush();
o.close();
}
%>
the program is not displaying the <h1>Vishal</h1>. Please assist on this

No comments:

Post a Comment