jdbc操作oracle的blob

由于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();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值