今天启动一个交接的项目,发现启动报错,如下错误提示:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:981) at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:339) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
解决办法
通过研究,发现如下解决办法,把mysql配置连接的url增加如下参数:
autoReconnect=true&allowPublicKeyRetrieval=true
完整的url例子:
url: jdbc:mysql://localhost:3306/dbname?useUnicode=true&useSSL=false&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowMultiQueries=true&autoReconnect=true&allowPublicKeyRetrieval=true
文章评论
Give your new site a boost, submit your site now to our free directory and start getting more clients
Add your site to all 35 of our business directories with one click here-
Add your site to all 35 of our business directories with one click here
Good job on the new site! Now go ahead and submit it to our free directory here
I was wondering if you wanted to submit your new site to our free business directory?