How can I avoid java.sql.SQLException due to an I / O error: connection reset?

After rebooting the SQL Server database, my Tomcat 6 Spring web applications get an SQL exception the first time I try to query the database. Note. Tomcat 6 continues to work during SQL Server reboot, and I use myBatis. An exception is the following:

org.springframework.dao.DataAccessResourceFailureException: Database query failed. Reason: java.sql.SQLException: I / O error: connection reset

Any subsequent requests are performed perfectly (without exception). How can I prevent this exception in the first request?

+4
source share
1 answer

Set up your pool to test connections before sending them to your application.

use testOnBorrow = true and (for example) validationQuery = "select 1" in your db pool connection

+1
source

All Articles