六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 246|回复: 0

jdbc操作oracle的blob

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-1-14 23:26:07 | 显示全部楼层 |阅读模式
由于thin驱动对setBinaryStream支持很差,没办法,只有采用笨点的方法了
connOracle = JDBCDataSource.getJDBCDataSource("jdbc.informix").getConnection();connOracle.setAutoCommit(false);BLOB blob = null;PreparedStatement pstmt = connOracle.prepareStatement("update ygjbxx set jbxx_photo=empty_blob() where jbxx_bh='"+ ygdh + "'");pstmt.executeUpdate();pstmt.close();PreparedStatement pstmt1 = connOracle.prepareStatement("select jbxx_photo from ygjbxx where jbxx_bh= ? for update");//for update必须要加pstmt1.setString(1, ygdh);ResultSet rset = pstmt1.executeQuery();if (rset.next()) {blob = (BLOB) rset.getBlob(1);}pstmt1.close();OutputStream out1 = blob.getBinaryOutputStream();int i = 0;while ((i = in.read()) != -1) {//InputStream为方法的参数out1.write(i);}out1.flush();out1.close();PreparedStatement pstmt2 = connOracle.prepareStatement("update ygjbxx set jbxx_photo=? where jbxx_bh='"+ ygdh + "'");pstmt2.setBlob(1, blob);pstmt2.executeUpdate();pstmt2.close();connOracle.commit(); 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表