这是怎么了 运行出错

来源:2-2 JDBC实战---打通数据库

慕圣5353598

2018-09-20 13:02


Exception in thread "main" 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(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:404)
 at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:988)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
 at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2251)
 at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2284)
 at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
 at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
 at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
 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:404)
 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
 at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source)
 at com.imooc.db.DBUtil.main(DBUtil.java:20)
Caused by: java.net.ConnectException: Connection timed out: connect
 at 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 com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:211)
 at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:300)
 ... 15 more


写回答 关注

1回答

  • weibo_陳朢逺
    2018-09-20 21:44:12

    数据库连接失败,检查一下你的URL有没有对

JDBC之 “ 对岸的女孩看过来”

一起领略JDBC的奥秘,为进一步学习集成框架打下良好的基础

99327 学习 · 856 问题

查看课程

相似问题