oracle 已达到 MaxOpenPreparedStatements 限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3416276/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:11:12  来源:igfitidea点击:

MaxOpenPreparedStatements limit reached

javaoraclejdbcapache-commons-dbcp

提问by alex543

I get this exception only for SOME database update in my code after several days of application running. Some of the requests passed, and some of them (the same java code) fail.

在应用程序运行几天后,我的代码中只有一些数据库更新才会出现此异常。一些请求通过了,其中一些(相同的java代码)失败了。

java.sql.SQLException: MaxOpenPreparedStatements limit reached
       at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:109)
       at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
       at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
       at com.prog.C.f(C.java:967)
       at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
       at java.lang.Thread.run(Thread.java:619)
Caused by: java.util.NoSuchElementException
       at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(GenericKeyedObjectPool.java:808)
       at org.apache.commons.dbcp.PoolingConnection.prepareStatement(PoolingConnection.java:107)
       ... 15 more

Datasource config:

数据源配置:

<bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close" lazy-init="true" scope="singleton">
        <property name="driverClassName" value="${jdbc.driver.class}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="poolPreparedStatements" value="true"/>
        <property name="maxOpenPreparedStatements" value="20"/>
    </bean>

There are allways available connections. How can I fix it? Thanks.

总是有可用的连接。我该如何解决?谢谢。

回答by duffymo

This means you probably aren't closing resources properly. You should be doing it in a finally block within the scope of the method that you create them in.

这意味着您可能没有正确关闭资源。您应该在创建它们的方法范围内的 finally 块中执行此操作。

回答by Chris Nash

You surely have prepared statements that are not being closed properly. A memory dump should help you find those.

您肯定已经准备好了没有正确关闭的语句。内存转储应该可以帮助您找到这些。

回答by Ghanshyam

Please try below in your configuration file :

请在您的配置文件中尝试以下操作:

db.pool.statements.enable=false

回答by Aravindh RS

you can set negative value. Setting negative value creates unlimited open prepared statements in cache.

您可以设置负值。设置负值会在缓存中创建无限的打开准备好的语句。