2009/08/12

MySQL connetion problem

The problem pops up when I was trying to connect to the MySQL database:

'The last packet successfully received from the server was41645 seconds ago.The last packet sent successfully to the server was 41645 seconds 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.com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was41645 seconds ago.The last packet sent successfully to the server was 41645 seconds 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 checked online (http://bbs.cnw.com.cn/thread-192473-1-1.html) and it's said that it's better to write the URL of the database in the following way:

jdbc:mysql://localhost:3306/test?autoReconnect=true&failOverReadOnly=false 

I've tried this trick but it's not working. Alternatively I checked the validity of the database connection, via 'conn.isValidate()' (this conn is the class 'JDCConnection' . Plz see my previous blog 'Using connection pool in java bean'). If it's not a validate connection any longer, I get a new connection from DriverManager again.

No comments:

Post a Comment