File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes How to retrieve image from ms access database through jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to retrieve image from ms access database through jsp" Watch "How to retrieve image from ms access database through jsp" New topic

How to retrieve image from ms access database through jsp

j u ray

Joined: Sep 21, 2009
Posts: 9
Hello All,
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 = "jdbcdbc:" + dataSourceName;
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( {
out.println( "</tr><tr>" );
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
while((!= -1 ){
} //while
out.println( "</tr></table></div>" )



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.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037

1. Don't use code in JSP to retrieve image or any other extensive computation.
2. Never ever try to serve binary data from JSP, use a servlet, JSP is for writing HTML with IMG tags

This question comes up all the time, search the forum.
Mehul Kumbhani

Joined: Apr 24, 2010
Posts: 9
If possible for you to get image without using OLE object in access use the image path to store image.

if you are using netbeans the you only need to give path of your current directory,
I am currently using this,so if possible do that.
I agree. Here's the link:
subject: How to retrieve image from ms access database through jsp
It's not a secret anymore!