Class.forName("Oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "111", "111");
//处理事务
con.setAutoCommit(false);
Statement st = con.createStatement();
//插入一个空对象
st.executeUpdate("update cc_ac03 set picture=empty_blob() where aac002=""+idcard+"""); //用for update方式锁定数据行 ResultSet rs = st.executeQuery(
"select picture from cc_ac03 where aac002=""+idcard+""");
if (rs.next()) {
//得到java.sql.Blob对象,然后Cast为oracle.sql.BLOB
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
//到数据库的输出流
OutputStream outStream = blob.getBinaryOutputStream();
// ByteArrayInputStream bis=upload.getFiles().getFile(0).getContentStream(); //这里用一个文件模拟输入流
// File file = new File(picture);
// InputStream fin = new FileInputStream(file);
// SmartUpload su = new SmartUpload();
//将输入流写到输出流
byte[] b = new byte[blob.getBufferSize()];
int len = 0;
while ( (len = stream.read(b)) != -1) {
outStream.write(b, 0, len);
//blob.putBytes(1,b);
}
//依次关闭(注意顺序)
// fin.close();
outStream.flush();
outStream.close();
con.commit();
con.close();
}解决的心得就是一定要把流文件存入数据库,而不是存本机的东东,不然就会去读本机的东西了。其实解决非常简单,过程却是痛苦的ByteArrayInputStream stream = upload.getFiles().getFile(0).getContentStream();这儿就已经得到流文件的值啦在64位WIN 7下安装32位XP和Ubuntu 11.04组成三系统Tomcat移植到weblogic上面乱码中文问题解决的方法相关资讯 Linux教程
- Linux教程:如何在命令行中查看目 (07/28/2014 12:22:23)
- Linux 修改root密码 (11/03/2012 07:53:38)
- su - root 与su root的区别 (06/06/2012 00:39:40)
| - Linux进程间通信:消息队列 (01/28/2013 09:43:00)
- U盘安装Linux开机无法启动解决方法 (10/07/2012 08:55:52)
- Windows 7/Linux 同步时间 (05/15/2012 06:17:55)
|
本文评论 查看全部评论 (0)