• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with com.mysql.jdbc.exceptions.jdbc4.CommunicationsException

 
Rob Hyx
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a webapp deployed to Tomcat 7 which is having intermittent database issues. Almost every morning when I come in the system has been idle over night and the application has issues connecting to the database. Reloading the webapp seems to fix the problem, which makes me think there's something wrong with the way I am getting connections. I have two systems, one being a development and the other for testing and this problem only happens with the latter. The exception I am getting is:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 60,431,937 milliseconds ago.The last packet sent successfully to the server was 60,431,937 milliseconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

I've tried adding the autoReconnect to my JDBC URL, but it hasn't made a difference. Here's how I grab my connection:



Here's my JNDI configuration:

 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are having this issue with testing server, have you compared the configuration files with the development server?
 
Rob Hyx
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I don't manage either database so I'm in the process of getting those configurations. The fact that I don't see the issue with the development stack makes me think it is a database issue, but the fact that restarting the webapp fixes it makes me think I'm doing something wrong in my application.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the config files are the same for the data source, then it's the code.

Then you should check whether you are closing all connections in your methods and I suggest your get connection class put the lookup inside the method rather than in the static block.
 
Rob Hyx
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually had the JNDI look up in the same method before, and I saw the same behavior. The only reason I separated them was I wasn't sure of the overhead from running it each time I want a connection.
 
K. Tsang
Bartender
Posts: 3585
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Hyx wrote:I actually had the JNDI look up in the same method before, and I saw the same behavior. The only reason I separated them was I wasn't sure of the overhead from running it each time I want a connection.


I'm pretty sure it makes no difference. Unless other ranchers here prove me wrong
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic