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]/?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