0
我用下面的代碼更新的Oracle的Clob:使用Oracle createTemporary更新的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()以便稍後使用;所以我的問題是,這是必要的?如果是,爲什麼?因爲我從谷歌搜索的一些示例代碼沒有這個過程。
我的第二個問題是,這是需要tempClob.close()在finally語句中;我們必須像使用連接之後關閉臨時clob一樣嗎?或者不需要這樣做,它會自動發佈?