4

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?

James
  • 2,876
  • 18
  • 72
  • 116
  • do you open and close the connection before and after each interaction, or are you leaving it open all the time? – Jeff Hawthorne Feb 13 '13 at 22:19
  • 1
    I do not explicitly close or open the connections. I have connection pool established as follows: – James Feb 13 '13 at 22:34
  • well the problem is the connection is broken when the sql server goes down and there's no way to do queries until it is reset (which is what is happening on your first query each time) all i can figure is either a) manually reset the jdbc connection after restarts, or b) test the connection periodically with a timed procedure perhaps and allow that to throw the exception and reset the connection – Jeff Hawthorne Feb 13 '13 at 22:41

1 Answers1

1

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

Stéphane
  • 867
  • 4
  • 7