getBinaryStream("Image")报IOException 大家遇见过这个问题吗?

whoknow 2004-07-08 09:27:04
private InputStream selectImage(long id){
Connection conn=null;
PreparedStatement stmt=null;
ResultSet rs=null;
InputStream ins=null;
try{
conn = setConnection();
String Sql="select name,image,id from image where id=?";
stmt = conn.prepareStatement(Sql);
stmt.setLong(1,id);
rs=stmt.executeQuery();
while(rs.next()){
ins=rs.getBinaryStream("image");
}
}catch(Exception e){
System.out.println("Image.selectImage.error."+e.toString());
}
finally{
return ins;
}
}
Image 列为Image类型,id是自增型主键,不知道为什么,用getBinaryStream()取Image列的时候,总是报java.io.IOException: JZ0I9: 该 InputStream 已关闭,多谢大家能指点一二!
...全文
218 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
whoknow 2004-07-08
  • 打赏
  • 举报
回复
嗨!实在没有人我就只能揭帖了.郁闷.
whoknow 2004-07-08
  • 打赏
  • 举报
回复
难道大家没有遇到过这个问题吗?
eaglecoody 2004-07-08
  • 打赏
  • 举报
回复
up
ChDw 2004-07-08
  • 打赏
  • 举报
回复
主要是你return ins;了,这里是不可以的,你一旦移动了rs.next
原来的ins就已经不可以用了
如果你需要的话,你必须将rs.getBinaryStream("image");的内容全部导入到一个byte[]中
并利用ByteArrayInputStream返回
whoknow 2004-07-08
  • 打赏
  • 举报
回复
up

81,087

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧