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