简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM