blob字段的修改

29 篇文章 0 订阅
/* 修改BLOB对象(是在原BLOB对象基础上进行覆盖式的修改) */
public static void blobModify(Connection con, Statement stmt,
String infile, String blobColumnName, String tabName, String id,
String idColumName) throws SQLException {
byte[] b = infile.getBytes();
/* 设定不自动提交 */
boolean defaultCommit = con.getAutoCommit();
con.setAutoCommit(false);
ResultSet rs=null;
try {
/* 查询CLOB对象并锁定 */
String sql_sel = "SELECT " + blobColumnName + " FROM " + tabName
+ " WHERE " + idColumName + "='" + id + "' FOR UPDATE";
String sql_up="update mutual set receive=empty_blob() where id='"+id+"'";
//System.out.println("blobModify String sql= "+sql);
stmt.executeUpdate(sql_up);
//con.commit();
rs=stmt.executeQuery(sql_sel);
if (rs.next()) {
//获取此CLOB对象 
oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob(1);
// System.out.println(clob);
// System.out.println("infile= "+infile);
OutputStream blobWriter = blob.getBinaryOutputStream();
//blob=oracle.sql.BLOB.empty_lob();
blobWriter.write(b, 0, b.length);
blobWriter.flush();
blobWriter.close();
}
//正式提交 
con.commit();/**/
} catch (Exception ex) {
/* 出错回滚 */
//con.rollback();
ex.printStackTrace();
}finally{
try{
if(rs!=null){
rs.close();
rs=null;
}
 }catch (Exception e) {}
}
/* 恢复原提交状态 */
//con.setAutoCommit(defaultCommit);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值