1. 程式人生 > >com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,873,183 milliseconds ago.  
The last packet sent successfully to the server was 59,873,186 milliseconds ago. 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 serve

在建立與MySQL的連線之後超過8個小時沒有再一次使用該連結,會報連線超時異常。
解決方法:
1、修改MySQL的wait timeout值,改成一個比28800大的值。比如864000,也就是該連結可以保持10天。wait_timeout=864000。但是最大值為2147483,超過之後還是會被解析為2147483。
2、在要使用該連線之前先判斷是否超時,如果超時,就重新建立連線。