dbcp:打开准备好的语句的数量
我的程序中出现 MaxOpenPreparedStatement 异常。我可以使用 getNumActive()/getNumIdle() 函数监视 GenericObjectPool 中的对象数量。我怎样才能获得连接&从 org.apache.commons.dbcp.BasicDataSource 对象准备语句池? 谢谢
I get MaxOpenPreparedStatement exception in my program. I can monitor number of objects in GenericObjectPool with getNumActive()/getNumIdle() functions. How can I get connection & prepared statement pools from org.apache.commons.dbcp.BasicDataSource object?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定实际问题的答案,但打开的准备好的语句的最大允许数量通常相当高。因此,我强烈怀疑导致您提出这个问题的技术问题是 JDBC 代码没有按照以下 JDBC 习惯用法正确关闭
finally
块中所有打开的语句:I am not sure about the answer on the actual question, but the maximum allowable amount of opened preparedstatements is usually pretty high. So I strongly suspect that the technical problem causing you to ask this question is that the JDBC code is not properly closing all the opened statements in the
finally
block as per the following JDBC idiom:DBCP 的 BasicDataSource 公开 maxOpenPreparedStatements 值数据源配置的。
此异常的存在似乎表明您打开了太多语句并且没有关闭它们:
DBCP's BasicDataSource exposes the maxOpenPreparedStatements value that the datasource is configured with.
The presence of this exception seems to indicate that you are opening too many statements and not closing them however:
您也许能够通过继承 BasicDataSource 来掌握 DBCP 内部结构,然后重写 createPoolableConnectionFactory 并用您自己创建的工厂替换语句池工厂(因此能够跟踪)。
与此处的其他答案一样,这似乎表明准备好的语句处于打开状态 - 在这种情况下,即使您关闭准备好的语句池(或完全停止使用连接池),您也会遇到相同的问题,这可能使原来的问题更容易调试。
You might be able to get a hold of the DBCP internals by subclassing BasicDataSource, then overriding createPoolableConnectionFactory and replacing the statement pool factory with one you create yourself (and thus are able to track).
As with the other answers here, this would seem to indicate prepared statements are being left open - in which case you'll have the same problem even if you turn prepared statement pooling off (or stop using a connection pool at all), which might make the original problem a lot easier to debug.