驱动程序没有从 IntelliJ IDEA 中的服务器收到任何数据包 [重复]
Posted
技术标签:
【中文标题】驱动程序没有从 IntelliJ IDEA 中的服务器收到任何数据包 [重复]【英文标题】:The driver has not received any packets from the server in IntelliJ IDEA [duplicate] 【发布时间】:2019-06-14 19:28:41 【问题描述】:我第一次尝试将我的 intelliJ java 项目与 mysql 连接,不幸的是我收到了这个错误:
com.mysql.cj.jdbc.exceptions.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 com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:677)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at sundos.ConnectionConfig.getConnect(ConnectionConfig.java:15)
at sundos.Main.main(Main.java:15)
Caused by: com.mysql.cj.exceptions.CJCommunicationsException:
Communications link failure
我已经添加了 mysql-connector。 这是我的一个简单代码:
public static Connection getConnect ()
Connection connection = null;
try
Class.forName("com.mysql.cj.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/test" , "root" , "12345");
catch (Exception e)
e.printStackTrace();
return connection;
【问题讨论】:
【参考方案1】:我在我的项目中遇到了同样的问题。我通过在连接 url 中使用服务器 ip 更改 localhost 来解决它
connection = DriverManager.getConnection("jdbc:mysql://192.168.3.3:3306/test" , "root" , "12345");
【讨论】:
【参考方案2】:确保您的 Mysql server
已启动并运行:
步骤:
-
检查
MySQL80
服务是否正在运行
尝试使用mysqlWorkbench
或任何其他工具连接到您的数据库
重新运行您的应用
注意:对于Windows,您可以通过搜索services
访问MySQL80
服务
【讨论】:
以上是关于驱动程序没有从 IntelliJ IDEA 中的服务器收到任何数据包 [重复]的主要内容,如果未能解决你的问题,请参考以下文章
如何从 IntelliJ IDEA 中的模型类生成 Flyway 迁移脚本?
从 intellij-idea 将代码样式格式设置导入 eclipse