mysql连接出错

来源:互联网 发布:圣诞节淘宝有活动吗 编辑:程序博客网 时间:2024/04/28 19:40

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failureThe 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(Unknown Source)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)at java.lang.reflect.Constructor.newInstance(Unknown Source)at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1118)at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:343)at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2308)at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2122)at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:774)at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:49)at sun.reflect.GeneratedConstructorAccessor5.newInstance(Unknown Source)at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)at java.lang.reflect.Constructor.newInstance(Unknown Source)at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:375)at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:289)at java.sql.DriverManager.getConnection(Unknown Source)at java.sql.DriverManager.getConnection(Unknown Source)at test.com.jalidata.util.SaveDateUtil.getConn(SaveDateUtil.java:23)at test.com.jalidata.saveDetail.SaveSkillLabel.saveResponsibilityPO(SaveSkillLabel.java:72)at test.com.jalidata.jsoup.ZhiLianSource.testurl(ZhiLianSource.java:199)at test.com.jalidata.jsoup.ZhiLianSource.geturl(ZhiLianSource.java:88)at test.com.jalidata.jsoup.ZhiLianSource.main(ZhiLianSource.java:253)Caused by: java.net.ConnectException: Connection refused: connectat java.net.DualStackPlainSocketImpl.connect0(Native Method)at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)at java.net.AbstractPlainSocketImpl.connect(Unknown Source)at java.net.PlainSocketImpl.connect(Unknown Source)at java.net.SocksSocketImpl.connect(Unknown Source)at java.net.Socket.connect(Unknown Source)at java.net.Socket.connect(Unknown Source)at java.net.Socket.<init>(Unknown Source)at java.net.Socket.<init>(Unknown Source)at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:292)... 17 more

解决办法:



jdbc.url=jdbc:mysql://localhost:3306/totosea?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false

在mysql的安装目录下找到my.ini
添加
wait_timeout=31536000
interactive_timeout=31536000

















0 0