62,614
社区成员
发帖
与我相关
我的任务
分享
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);
}
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呢
}
}