oracle blob插入不进去图片

hailun 2008-03-15 05:21:49

//byte[] buf = new byte[2048]; 这个时候可以插入.txt文件,但插入不进去图片不知道为什么
byte[] buf = new byte[204800]; //这个时候去可以插入图片,原因不知道为啥
int len = 0;
if((len = bis.read(buf,0,buf.length)) != -1) { //如果为bis.read()没有参数的话,.txt,.jpg等都插入不进去,不知道为什么
os.write(buf, 0, len);
os.flush();
}
...全文
148 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
iihero 2008-03-16
  • 打赏
  • 举报
回复
bis是什么,BinarayInputStream,当然要带参数。不然不知道到底读取多少字节啊。
liyubin709 2008-03-16
  • 打赏
  • 举报
回复
OutputStream out = response.getOutputStream();
Product item = Product();
java.sql.Blob picture = item.getPicture();
InputStream in = picture.getBinaryStream();
byte[] b = new byte[512];
int len = in.read(b);
while(len != -1){
out.write(b, 0, len);
len = in.read(b);
}


//试一下
zhsjun 2008-03-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hailun 的回复:]
byte[] buf = new byte[2048];
bis.read(buf,0,buf.length)就是说我要读取上面定义的那个buf个字节是吗?而且是只读取这些????
[/Quote]
每次读取的最多的字节数,在使用完os,最好调用flush将缓存中的数据全部输入到目标位置
如果向数据库中插入图片,最好采用PreparedStatement进行,不知道你这里的os是写到那里去了
hailun 2008-03-16
  • 打赏
  • 举报
回复
byte[] buf = new byte[2048];
bis.read(buf,0,buf.length)就是说我要读取上面定义的那个buf个字节是吗?而且是只读取这些????

62,623

社区成员

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

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