Posted on 2006-07-24 12:31 
壮士日志 阅读(551) 
评论(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());
    }