惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - CowboyRyan

Agile WDR 读书笔记 获取 光盘信息 关于 python 的注释 python 调用 c 模块 jquery学习总结 之 dialog Excel开发总结:关于C#导入导出excel的那些琐事 转:HTML及XML语言的转义字符 - CowboyRyan - 博客园 关于SVN:合并提交是如何操作的? ActiveSync 无法同步解决记录 RH 基本文件操作命令 捣鼓Ubuntu下RPM安装 vm下linux 界面切换 杂 感 悟 测试杀毒软件强不强 【Transformer Ⅱ 】观感 ExtJs 笔记1 关于 Windows Server 2008 许可证到期 使用PowerDesigner生成HTML功能 PowerDesigner建立已存在字段索引
hibernate 将图片写入 oracle blob
CowboyRyan · 2012-12-30 · via 博客园 - CowboyRyan

用JDBC操作Blob最基本的思路是:先插入一条包含空Blob的记录,然后立即将该条记录用行锁定的方式打开,得到改Blob字段的引用,从中得到一个输出流,将byte[]数据写入后提交。hibernate操作的基本思路也是一致的。

参考url:

http://biekwo.iteye.com/blog/323393

http://bbs.csdn.net/topics/60009941

由于如果不是使用oracle 操作 blob,会报 不支持新特性的错误

robbin的这篇也可以

http://www.iteye.com/topic/254

这是另一个思路,但是我没有试验成功

http://bbs.csdn.net/topics/220063661

如果报这个错误

不允许的操作: streams type cannot be used in batching

参考这个url

http://hsyd.iteye.com/blog/320579

我的代码

 1 publicint add(User u) {
 2 
 3 // TODO Auto-generated method stub
 4 
 5 try{
 6 
 7 //获取数据id
 8 
 9  
10 
11 u.setId(GetMax());
12 //空的blob
13 u.setImage(Hibernate.createBlob(newbyte[1]));
14 Session session = sessionFactory.openSession();
15 
16 transaction = session.beginTransaction();
17 session.save(u);
18 
19 session.flush();
20 
21 session.refresh(u,LockMode.UPGRADE);
22 
23 //获取引用
24 
25 SerializableBlob sb = (SerializableBlob)u.getImage(); 
26 
27 BLOB blob = (oracle.sql.BLOB)sb.getWrappedBlob();  
28 
29 OutputStream out =((oracle.sql.BLOB)blob).getBinaryOutputStream(0);
30 
31  
32 
33  
34 
35 File file = new File("/Users/apple/Downloads/project.png"); 
36 
37 FileInputStream fis = new FileInputStream(file); 
38 
39     byte[] buff = newbyte[fis.available()]; 
40 
41     fis.read(buff); 
42 
43     fis.close(); 
44 
45     out.write(buff); 
46 
47     out.close();
48 
49  
50 
51 // When done close the streams
52 
53  
54 
55 //
56 
57 session.flush();
58 
59 //
60 
61 transaction.commit();
62 
63 System.out.println("save success");
64 
65 }catch(Exception e){
66 
67 System.out.println(e.getMessage());
68 
69 return 0;
70 
71 }
72 
73 return 1;
74 
75 }