如何从数据库中读图片 我用的是SQL server2000 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主可以使用下面代码,其中conn要自己定义,showImage要换成自己的Sql语句:<% String showImage = " select * "+ " from t_attachment "+ " where upload_id='1210832040218' " ; BufferedInputStream inputImage = null; try{ Statement st = conn.createStatement(); ResultSet rs=st.executeQuery(showImage); String filename=""; while(rs.next()) { Blob blob = (Blob)rs.getBlob("BINARYFILE"); filename=rs.getString("FILENAME"); inputImage = new BufferedInputStream(blob.getBinaryStream()); } BufferedImage image = null; image=ImageIO.read(inputImage); ServletOutputStream sos = response.getOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos); encoder.encode(image); inputImage.close(); } catch(SQLException se) { se.printStackTrace(); } catch(IOException ie) { ie.printStackTrace(); }%></body><%}catch(Exception e){ }finally{ closeConn(conn);}%> 把图片的路径地址写入数据库,读取的时候直接用路径,再者可以转换成二进制,放入数据库中blob?很少用sqlserver,大致就以上两种,一般推荐使用第一种方式 求助。页面初始化报错 hibernate 貌似映射错了!求高手过路看下!谢谢 求助.想指定网页中让某个代码优先显示 struts2,算麻烦的问题 帮忙找缺点 www.cnlicai.com jsp连数据库问题 有没有一些国外的写的比较好的js日期选择输入控件? 山寨qq出现问题,不知道是不是管道出问题还是什么,求问啊。 是高手,就过来看!!! 请问有什麽好的编辑jsp的软件? 怎样解决我这个关于删除的问题,由jsp+servle+javabean模式 windows7配置jdk不好使
String showImage = " select * "+
" from t_attachment "+
" where upload_id='1210832040218' " ;
BufferedInputStream inputImage = null;
try{
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery(showImage);
String filename="";
while(rs.next()) {
Blob blob = (Blob)rs.getBlob("BINARYFILE");
filename=rs.getString("FILENAME");
inputImage = new BufferedInputStream(blob.getBinaryStream());
}
BufferedImage image = null;
image=ImageIO.read(inputImage);
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
inputImage.close();
} catch(SQLException se) {
se.printStackTrace();
} catch(IOException ie) {
ie.printStackTrace();
}
%>
</body>
<%}
catch(Exception e){
}
finally{
closeConn(conn);
}
%>