oracle817数据删除,Oracle817读取CLOB有关问题解决

这篇博客记录了在使用Hibernate整合Oracle817数据库时遇到的Clob字段读取异常。作者尝试了更换多个驱动但问题依旧,最终通过Oracle JDBC目录下的demo找到解决方案,通过CallableStatement调用Oracle特定的DBMS_LOB方法来读取Clob内容。这是一个针对Oracle特定版本的驱动和Hibernate集成的疑难杂症实例。
摘要由CSDN通过智能技术生成

最近搞的Hibernate集成oracle817,读取Clob字段时一直报错:

io 异常: 类型长度大于最大值;

百度、google大家都说是驱动问题,换了N个驱动一样的错误,官网oracle817的驱动是.zip的,搞得不知怎么用,总是加载不到驱动,直接解压到classes文件中,报错:

java.lang.AbstractMethodError

最后看到oracle的jdbc目录下有demo,终于找到了正解:

// 读取CLOB字段

static String dumpClob(Connection conn, CLOB clob) throws Exception {

String clobStr = "";

CallableStatement cstmt1 = (CallableStatement) conn

.prepareCall("begin ? := dbms_lob.getLength (?); end;");

CallableStatement cstmt2 = (CallableStatement) conn

.prepareCall("begin dbms_lob.read (?, ?, ?, ?); end;");

cstmt1.registerOutParameter(1, Types.NUMERIC);

cstmt1.setClob(2, clob);

cstmt1.execute();

long length = cstmt1.getLong(1);

long i = 0;

int chunk = 10;

while (i < length) {

cstmt2.setClob(1, clob);

cstmt2.setLong(2, chunk);

cstmt2.registerOutParameter(2, Types.NUMERIC);

cstmt2.setLong(3, i + 1);

cstmt2.registerOutParameter(4, Types.VARCHAR);

cstmt2.execute();

long read_this_time = cstmt2.getLong(2);

String string_this_time = cstmt2.getString(4);

clobStr += string_this_time;

// System.out.print("Read " + read_this_time + " chars: ");

// System.out.println(string_this_time);

i += read_this_time;

}

cstmt1.close();

cstmt2.close();

return clobStr;

}

//读取BOLB

static void fillBlob(Connection conn, BLOB blob, long length)

throws Exception {

CallableStatement cstmt1 = (CallableStatement) conn

.prepareCall("begin dbms_lob.write (?, ?, ?, ?); end;");

long i = 0;

long chunk = 10;

byte[] data = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

while (i < length) {

cstmt1.setBlob(1, blob);

cstmt1.setLong(2, chunk);

cstmt1.setLong(3, i + 1);

data[0] = (byte) i;

cstmt1.setBytes(4, data);

cstmt1.execute();

i += chunk;

if (length - i < chunk)

chunk = length - i;

}

cstmt1.close();

}

这种问题感觉应该比较常见,在网上竟没有解决方法,特此记录一下,供遇到同样问题的人员参考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值