jdbc操作oracle的blob

本文讨论了thin驱动在处理setBinaryStream时存在的局限性,并提供了一个替代方案来实现数据的高效存储与检索。通过使用JDBCDataSource获取连接、执行更新操作、查询并读取BLOB数据,然后利用OutputStream进行数据写入,最后更新数据库以完成数据的替换过程。此方法确保了数据的正确性和完整性,避免了直接使用thin驱动时可能遇到的性能瓶颈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

由于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、付费专栏及课程。

余额充值