Hello Everybody,
I have stored images in ms access. The field name is "image" and the data type is OLE Object. I have stored an image with ".bmp" extension. In the database in the record it is showing "Bitmap Image". Now I am using JSP to retrieve this image and display it in the web page.
The coding is::
<%
InputStream sImage;
try {
String dataSourceName = "pictures";
String dbURL = "jdbc:odbc:" + dataSourceName;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
String sTable = "imagetable";
Connection cn = null;
Statement st = null;
ResultSet rs = null;
String sSql = "SELECT machine_image,machine_name,machine_details FROM " + sTable;
cn = DriverManager.getConnection(dbURL,"","");
st = cn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs = st.executeQuery( sSql );
ResultSetMetaData rsmd = rs.getMetaData();
int n = rsmd.getColumnCount();
out.println( "<div align=\"center\">" + "<table border=2 cellspacing=2 bgcolor=LightGreen width=400><tr>" );
while(rs.next()) {
out.println( "</tr><tr>" );
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/bmp");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
} //while
out.println( "</tr></table></div>" )
%>
<%
}//try
catch (Exception err) {
out.println("ERROR" + err);
}
%>
the output which i am getting is:
in the text box where the image is supposed to be displayed , string value is being displayed.
i am not able to get the image.
i have gone through net but not able to get any proper solution.
I will be grateful if anyone can help me. please help me as soon as possible.
thanks in advance.