Hi people,
There is a problem with servlet reading images in database.
Database used :Ms-Access
Exception is:[ Microsoft ][ODBC Driver Manager]Invalid cursor state
Code:
************************************************
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Dbreader extends HttpServlet
{
Connection con;
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc
dbc:jspdata");
}
catch(Exception e)
{System.out.println("Exception is!"+e);
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
try{
res.setContentType("image/gif");
ServletOutputStream out=res.getOutputStream();
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from ImageTable where imageid=1");
BufferedInputStream gifData=new BufferedInputStream(rs.getBinaryStream("Image"));
System.out.println("value of gif"+gifData.toString());
byte buf[]=new byte[4*1024];
int len;
while((len=gifData.read(buf,0,buf.length))!=-1)
{out.write(buf,0,len);
}
}
catch(Exception e)
{System.out.println("Exception !"+e);}
}
}
Please help me!
Thanx in advance...