關(guān)于ORA-01000: maximum open cursors exceeded的異常
Posted on 2006-07-24 12:31 壯士日志 閱讀(544) 評(píng)論(0) 編輯 收藏以前寫(xiě)jdbc相關(guān)的程序一直沒(méi)有注意到 statement/resultset 是需要關(guān)閉的,直到最近在一個(gè)系統(tǒng)里面發(fā)現(xiàn)了這個(gè)“maximum open cursors exceeded”的異常。
通過(guò)查找相關(guān)文檔,原來(lái)一個(gè)statement通常會(huì)對(duì)應(yīng)一個(gè)db cursor,如果大量使用statement而不關(guān)閉就會(huì)引起此異常,關(guān)閉的代碼很簡(jiǎn)單:
if(rs!=null)?? //ResultSet
????try {
?????rs.close();
????} catch (SQLException e1) {
?????logger.error(e1.getMessage());
????}
???if(pst!=null)? //PreparedStatement??
????try {
?????pst.close();
????} catch (SQLException e1) {
?????logger.error(e1.getMessage());
????}