關(guān)于ORA-01000: maximum open cursors exceeded的異常
Posted on 2006-07-24 12:31 壯士日志 閱讀(541) 評論(0) 編輯 收藏以前寫jdbc相關(guān)的程序一直沒有注意到 statement/resultset 是需要關(guān)閉的,直到最近在一個系統(tǒng)里面發(fā)現(xiàn)了這個“maximum open cursors exceeded”的異常。
通過查找相關(guān)文檔,原來一個statement通常會對應一個db cursor,如果大量使用statement而不關(guān)閉就會引起此異常,關(guā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());
????}