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

推荐订阅源

Forbes - Security
Forbes - Security
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
SegmentFault 最新的问题
Y
Y Combinator Blog
Recorded Future
Recorded Future
博客园 - Franky
I
InfoQ
T
The Blog of Author Tim Ferriss
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
Cloudbric
Cloudbric
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Check Point Blog
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
T
Threat Research - Cisco Blogs
U
Unit 42
N
Netflix TechBlog - Medium
The Cloudflare Blog
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
美团技术团队
T
Troy Hunt's Blog
Engineering at Meta
Engineering at Meta
H
Heimdal Security Blog
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
B
Blog
S
Securelist
H
Hacker News: Front Page
Google Online Security Blog
Google Online Security Blog
G
Google Developers Blog

博客园 - 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 }