`

关于ORACLE游标的问题(ORA-01000 maximum open cursors exceeded)

 
阅读更多

 这几天准备项目上线前发现问题,ORA-01000 maximum open cursors exceeded 而且好几个功能出现类似问题

在网上也查了资料,都说是游标越界了 建议增大游标,后来架构师检查了下代码,原来是preparedStatement没有关闭,汗!

 

Session hibernateSession = (Session) Component.getInstance("hibernateSession");
        String hql = "select current_timestamp from dual";
        Connection conn = hibernateSession.connection();
        try {
            PreparedStatement pstmt = conn.prepareStatement(hql);
            ResultSet rs = pstmt.executeQuery();
            if (rs.next()) {
                Timestamp time = rs.getTimestamp("current_timestamp");
                return time;
            }
        } catch (SQLException e) {   
        }
        return new Timestamp(System.currentTimeMillis());

此方法没有关闭 pstmt 、rs、conn

 

使用了框架之后,此类问题很难发现,同时也是非常低级的问题   以后一定要注意,手动取得连接、创建PreparedStatement 获得 ResultSet  记得一定关闭资源!

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics