This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rpt : Image Inesertion some1 check this code

 
akilan kandaswamy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai ,
I tried to retrieve an image from MSACCESS using the following code im getting an Exception IOException:MEthod not implemented some1 pls help me, how to enter an imae into an DataBase?

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GetImage4 extends HttpServlet
{
Connection con;
Statement st;
ResultSet rs;
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try{
res.setContentType("image/gif");
PrintWriter out=res.getWriter();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:sasi");
st=con.createStatement();
rs=st.executeQuery("SELECT * FROM IMAGE");

rs.next();

BufferedInputStream bis=new BufferedInputStream(rs.getBinaryStream(2));
byte[] bb=new byte[4 * 1024];
int dd=rs.getInt(1);

int len=0;
while(len!=-1)
{ len=bis.read(bb,0,bb.length);
out.print(len);
}
}
catch(Exception e)
{ System.out.println(e);e.printStackTrace(); }
}
}
 
David Freels
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use PreparedStatement instead of Statement when retrieving data from BLOBs or CLOBs.
David
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic