Java 超过最大游标数SQLException--配置问题或游标泄漏?

Java 超过最大游标数SQLException--配置问题或游标泄漏?,java,sql,oracle,database-connection,sqlexception,Java,Sql,Oracle,Database Connection,Sqlexception,我正在通过Java调用一个SQL过程。执行代码时,日志中出现SQL异常- java.sql.SQLException:ORA-01000:超过最大打开游标数 我也经历过类似的问题,并尝试过这个- 将OpenU游标从30000增加到40000 在try和finally块中关闭语句 但这并没有解决问题。我的代码有问题吗 这是我的Java代码- public static void buildingHelpContent(String p_id) throws Throwable{ C

我正在通过Java调用一个SQL过程。执行代码时,日志中出现SQL异常- java.sql.SQLException:ORA-01000:超过最大打开游标数

我也经历过类似的问题,并尝试过这个-

  • 将OpenU游标从30000增加到40000
  • 在try和finally块中关闭语句
  • 但这并没有解决问题。我的代码有问题吗

    这是我的Java代码-

    public static void buildingHelpContent(String p_id) throws Throwable{
            Connection conn = ExtractHP.getConnection();
            CallableStatement cs = null;
            log.debug("arguments for COMP.Help.build_hp_data  p_id=  "+p_id);
            try {
                cs = conn.prepareCall("{call COMP.Help.build_hp_data(?)}");
                cs.setString(1, p_id);
                cs.execute();
                if(cs!=null)            
                    cs.close();
    
            } catch (SQLException e) {
                log = ExtractHP.getLogger();
                log.debug("!!! Java Exception !!!\n");
                log.error("Exception while executing the procedure for ID ...."+ p_id, e);          
            }
            finally{
                if(cs!=null)
                    cs.close();
            }
        }
    

    您没有关闭连接,您可以使用
    try with resources
    块(不使用
    finally
    ):

    在java 6中,最后在
    中关闭连接:

    finally{
            if(cs!=null)
                cs.close();
            if(conn!=null)
                conn.close();
        }
    

    我假设问题出在您的sql代码中。现在您已经向
    finally
    块添加了
    close
    调用,我建议您从
    try
    块中删除
    close
    代码。正如@user7294900所说,添加
    if(conn!=null)conn.close()
    finally
    块。的答案可能会帮助youHi@BobJarvis我添加了conn.close();在最后一个街区。但是现在开始下面的异常:java.sql.SQLException:Closed connectionsanks用于回复。不幸的是,这段代码非常旧,是用Java1.6编写的。无法使用try with resources。@RichaSharma查看我的更新答案,添加
    conn.close()
    最后
    +1以获取您的建议@user7294900。在finally块中添加conn.close()之后,现在我得到了一个新的异常:java.sql.SQLException:Closed Connection Throw and Throwable的java代码中有什么问题吗?@RichaSharma我建议您使用
    ExtractHP.getConnection()中的代码打开一个新问题
    
    finally{
            if(cs!=null)
                cs.close();
            if(conn!=null)
                conn.close();
        }