使用JDBC将Clob更新为oracle时出现问题

时间:2011-12-10 14:28:53

标签: java sql oracle jdbc oracle10g

我使用以下代码更新clob:

pStmt = conn.prepareStatement("SELECT DETAILS FROM PROGRAM_HISTORY WHERE id = 12");
rset = pStmt.executeQuery();
Clob detailsClob= rset.getClob(1);
System.out.println(detailsClob.length()); output: 100

Writer writer = ((oracle.sql.CLOB)detailsClob).getCharacterOutputStream();
writer.write("add more details"); 
writer.flush();
writer.close();
System.out.println(detailsClob.length()); output: 100

pStmt = conn.prepareStatement("UPDATE PROGRAM_HISTORY SET DETAILS = ? WHERE ID = 12");
pStmt.setClob(1, detailsClob);
pStmt.execute();

问题是clob属性无法正确更新,我想使用新字符串替换Oracle中现有的clob值,但是没有替换,两次打印的长度是相同的。

所以理想的是,作者只是附加了后面的值,是否应该清空作者空?我怎么能这样做?

先谢谢,大家能给我一些想法吗?

0 个答案:

没有答案