[英]Will C3P0 ComboPooledDataSource getConnection() always return valid Connection?
What are possible return values from that method? 该方法可能返回什么值?
The question is should I check if the returned connection isn't null or is valid? 问题是我应该检查返回的连接是否为空或有效? Or should I just catch the SQLException?
还是应该只捕获SQLException? Is the returned connection always valid if no SQLException is thrown?
如果未抛出SQLException,返回的连接是否始终有效?
From my experience (and from javadoc of DataSource ) this method will return you a connected Connection, you can use to query your database. 根据我的经验(以及DataSource的 javadoc),该方法将为您返回连接的Connection,您可以使用它来查询数据库。 If pool is exhausted, method will block until a Connection becomes available.
如果池已用尽,则方法将阻塞,直到连接可用为止。
In the unlikely event of a loss of
cabin pressure
database connectivity, these errors will happen all over you application. 万一发生
机舱压力
数据库连接丢失的情况,这些错误将在整个应用程序中发生。 If you want to check your connections at checkout / at regular intervals - c3p0 has configuration options that do that for you. 如果您想在结帐时/定期检查连接-c3p0的配置选项可以为您完成此任务。
See http://www.mchange.com/projects/c3p0/#testConnectionOnCheckout for configuration options. 有关配置选项,请参见http://www.mchange.com/projects/c3p0/#testConnectionOnCheckout 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.