Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. the driver has not received any packets from the server.
網上查到的符合我環境的,應該是我的連接數太多,導致MySQL連接數用完,所以優化代碼,讓多次連接公用一個connection;連接用完後,關閉。
此外,設置自動重連也能有一定幫助,但ms官方不太建議設置自動重連。
自動重連,在java中只需把連接的server字符串中添加:
jdbc:mysql://[ip]:[port]/[table]?autoReconnect=true&failOverReadOnly=false&maxReconnects=10
其中這兩篇文章比較好:
http://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai