James
James

Reputation: 3184

How can I avoid a java.sql.SQLException due to I/O Error: Connection reset?

After a SQL Server database restart, my Tomcat 6 Spring web applications receives an SQL exception on the first attempt to query the database. Note: Tomcat 6 has continued to run during the SQL Server restart and I'm using myBatis. The exception is as follows:

org.springframework.dao.DataAccessResourceFailureException: Error querying database. Cause: java.sql.SQLException: I/O Error: Connection reset

Any subsequent queries execute fine (without exception). How can I prevent this exception on the first query?

Upvotes: 4

Views: 7727

Answers (1)

Stéphane
Stéphane

Reputation: 877

Set up your pool to test connections before giving them to your application

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

Upvotes: 1

Related Questions