问题描述
我有一个带有 Java 后端的 Web 应用程序,它使用 Tomcatjdbc-pool 用于数据库连接.这工作正常.
I have a web-app with a Java back-end that uses Tomcat jdbc-pool for database connections. This works fine.
但是,我在将其导出到其他位置之前尝试对其进行万无一失,最近发生了一个场景,有人重新启动了 SQL Server 数据库服务,但没有重新启动 Tomcat 服务.这导致了 SQLException: java.sql.SQLException: I/O Error: Connection reset by peer: socket write error
直到我重新启动 Tomcat,迫使 jdbc-pool 数据源重新连接.
However I am trying to foolproof it before exporting it to other locations, and recently a scenario occurred where someone restarted the SQL Server database service but did not restart the Tomcat service. This caused a SQLException: java.sql.SQLException: I/O Error: Connection reset by peer: socket write error
until I restarted Tomcat, forcing the jdbc-pool datasource to reconnect.
我在 Tomcat jdbc-pool 文档中寻找某种配置来告诉数据源尝试重新连接,但我找不到任何东西.
I looked for some kind of a configuration in the Tomcat jdbc-pool docs to tell the datasource to attempt to reconnect but I couldn't find anything.
有谁知道是否有某种配置,或者我应该在每次请求之前检查这个条件吗?
Does anyone know if there is some kind of configuration for this or should I check this condition before each request?
推荐答案
不是 100% 确定这是否是您的问题,而是在 http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency 它说你可以使用 testOnBorrow
带有 validationQuery
.
Not 100% sure if this is your problem but on http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency it says you can use testOnBorrow
with a validationQuery
.
<Resource type="javax.sql.DataSource"
...
testOnBorrow="true"
validationQuery="SELECT 1"
removeAbandoned="true"
/>
这篇关于数据库重启后尝试重新连接jdbc池数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!