【发布时间】:2012-01-17 17:07:32
【问题描述】:
我使用以下代码更新 Oracle Clob:
CLOB tempClob = null;
try {
Connection conn = getConnection();
PreparedStatement = = conn.prepareStatement("UPDATE PROGRAM_HISTORY SET DETAILS = ? WHERE ID = 12");
tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION);
tempClob.open(CLOB.MODE_READWRITE);
Writer tempClobWriter = tempClob.getCharacterOutputStream();
tempClobWriter.write(clobData);
tempClobWriter.flush();
tempClobWriter.close();
tempClob.close();
pStmt.setClob(1, tempClob);
pStmt.execute();
} catch (Exception ex) { // Trap errors
System.out.println(" Error Inserting Clob : "+ex.toString());
ex.printStackTrace();
}finally{
if(tempClob != null ) tempClob.freeTemporary();
opstmt.close();
conn.close();
}
如您所见,在创建临时 clob 后,我使用了 tempClob.open(CLOB.MODE_READWRITE); 打开并使用 tempClob.close() 稍后关闭;所以我的问题是这有必要吗?如果是,为什么?因为我从谷歌搜索的一些示例代码没有这个过程。
我的第二个问题是,在 finally 语句中是否需要 tempClob.close() ;用完后我们必须像连接一样关闭临时clob吗?或者不需要这样做它会自动释放?
【问题讨论】:
标签: java sql oracle jdbc oracle11g