Connection con=DriverManager.getConnection(url,"demo","demo");
PreparedStatement sql=con.prepareStatement("select * from test_img WHERE id = " + image_id);
ResultSet rs = sql.executeQuery();
rs.next();
//输入img字段内容到in
InputStream in = rs.getBinaryStream("img");
//以下可是任何处理,比如向页面输出:
response.reset();
//此处的image/jpeg似乎与显示的图片格式无关
//因为我显示jsp和gif都没有错误。icech不是很懂,都是参考别人的。
response.setContentType("image/jpeg");
byte[] b = new byte[1024];
int len;
while((len=in.read(b)) >0)
response.getOutputStream().write(b,0,len);