java写大字段问题

simonyo 2011-08-28 09:58:02
在插入clob字段时,有时会出记录插入,但是CLOB字段的内容提要没有被插入. 代码片断如下所示 , 请帮忙分析下原因


PreparedStatement pstmt = null;
ResultSet rs = null;
try{
//step1: 插入一条空数据
pstmt = conn.prepareStatement("insert into T_BO (SEQ, C_CLOG) VALUES (0,EMPTY_CLOB() ) " ;
if (pstmt.executeUpdate() == 1) {
log("Successfully inserted a clob record");
}
//step2: 插入CLOB字段
pstmt=conn.prepareStatement("select bo from T_BO where seq=0 for update nowait");
rs=pstmt.executeQuery();
String clobData = "this is a test string.";
while(rs!=null&&rs.next()){
oracle.sql.CLOB clob= (oracle.sql.CLOB)rs.getClob(1);
Writer outstream = clob.getCharacterOutputStream();
outstream.write(clobData,0,clobData.length());
outstream.close();
break;
}
conn.commit();
} catch (SQLException e) {
printErr(e);
} catch (Exception ex) {
printErr(ex);
} finally {
close_conn(rs, pstmt);
}
...全文
185 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
打油的程序员 2011-08-28
  • 打赏
  • 举报
回复
while循环部分改为下面的代码试试


if(rs!=null){
while(rs.next()){
oracle.sql.CLOB clob= (oracle.sql.CLOB)rs.getClob(1);
Writer outstream = clob.getCharacterOutputStream();
outstream.write(clobData.toCharArray(),0,clobData.length());
outstream.flush();
outstream.close();
//break;//为啥这样写,如果这样写,何必用while呢
}
}

simonyo 2011-08-28
  • 打赏
  • 举报
回复
插入大字段,分两步,先插入记录,其CLOB字段为空,第二步再写入CLOB字段
问题描述:有时会出现CLOB字段没有插入的情况.

打油的程序员 2011-08-28
  • 打赏
  • 举报
回复
什么是内容提要?能否举个例子哪些信息成功插入了,那些信息需要插入却没插入

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧