I've the following code to retrieve an image from mysql and want to disply it on JSP but the web page is displayed and the image not. what is wong with this code...
<tbody>
<tr>
<td> <%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page language="java"%>
<%@ page session="true"%>
<%@ page import="java.sql.*"%>
<% Blob image = null; Connection con = null; Statement stmt = null; ResultSet rs = null; String iurl1=null;
byte[] imgData = null ; String DBname = "Rest_Tucan"; String userName = "aaks1962"; String password = "1962";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"
+ DBname + "?UseUnicode=true&charachterEncoding=UTF-8");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from imagesTable where imagesTableCode = 1");
while(rs.next()){
image = rs.getBlob("imagesTableBig");
}
// display the image
imgData = image.getBytes(1,(int)image.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
}catch (SQLException e) {
e.printStackTrace();
};
%>
</td>