hibernate blob读取图片问题
来源:互联网 发布:南极星全球通软件 编辑:程序博客网 时间:2024/05/17 22:58
我的环境是mysql+hibernate3.2.6 读取图片
1 domain:
我使用的 Blob 类型
@Lob
@Basic(fetch=javax.persistence.FetchType.EAGER)
@Column(name="content",columnDefinition="MEDIUMBLOB NOT NULL")
private Blob content;
2 action:
我可以保存,但读取到页面上时很慢
BlobService blobService = (BlobService)this.getApplicationContext().getBean("blobServiceTrans");
String contentType = "application/octet-stream;chartset=utf-8";
response.setContentType(contentType);
response.addHeader("Content-Disposition", "attachment;");
try {
OutputStream os = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
String id = request.getParameter("id");
//速度太慢
BlobIns blobIns = blobService.findBlobInsById(id);
Blob content = blobIns.getContent();
int length = (int)content.length();
byte[] temp = content.getBytes(1,length);
//InputStream is = blobIns.getContent().getBinaryStream();
//byte[] temp = new byte[1024*10];
// int i = 0;
// while((i = is.read(temp)) != -1){
// bos.write(temp,0,i);
// }
bos.write(temp);
bos.flush();
bos.close();
os.close();
//content.free();
//is.close();
} catch (IOException e) {
System.out.println("读取文件异常!");
e.printStackTrace();
}
我使用了2种办法,但都很慢,昨晚在家写的和以上的查不多但却很快就看到图片了,(图片为1.5m)
(1)直接使用Blob.getBinaryStream();得到输入流-->向输出流写内容
(2)使用Blob.getBytes(1,length)得到内容-->response的输出流里写
请教大家是什么原因?谢谢
问题补充:
谢谢huangnetian对本问题的关注,这个问题目前还没有明确的原因,后来我找公司的老同志问了问,据说可能跟容器有关如tomcat的缓存等,这2天忙着做其他的东西也没顾上,有时间好好研究下吧
- hibernate blob读取图片问题
- Hibernate读取Blob图片
- hibernate从sqlserver数据库中读取图片 Image (Blob)
- struts2+Hibernate 读取oracle blob 字段中的图片
- Blob存储读取图片
- JSP Oracle BLOB 图片读取
- Oracle读取Blob数据-通过hibernate
- blob数据读取(一般是图片)
- grails从数据库读取blob显示图片
- Java 连接 MySQL读取 Blob 生成图片
- java读取图片插入blob,并取出
- 从oracle中读取blob图片资源
- 使用JDBC和Hibernate在oracle中插入和读取Blob数据的图片的java程序
- hibernate+mysql图片读取
- hibernate读取图片例子
- hibernate Blob
- 用hibernate 读取BLOB字段保存到数据库中
- Mysql 用blob存储图片问题 GBK
- 少抱怨,多积极主动。少浮躁,多塌实!!!
- 非泛型集合使用Linq
- (转)Loadrunner并发用户与集合点深入的讨论(经典)
- PHP客户端缓存控制
- Winform 窗口加载实例(二)-----TabControl
- hibernate blob读取图片问题
- 你的钱来自哪里?
- Linux下iptables原理解析
- 他是一扇有益之门 - A.J.克朗宁小诗
- 删除Windows2000/XP/2003 默认共享
- (转)Loadrunner并发用户与集合点深入的讨论(经典)
- windows禁用端口
- 点到点之间的建立隧道方法
- 公司开会有感