Драйвер не получил никаких пакетов с сервера в IntelliJ IDEA - PullRequest
0 голосов
/ 21 января 2019

Я пытаюсь подключить свой проект 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-коннектор.вот мой простой код:

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 Ответ

0 голосов
/ 17 апреля 2019

У меня такая же проблема в моем проекте.Я решил это, изменив localhost с ip сервера в URL-адресе соединения

 connection = DriverManager.getConnection("jdbc:mysql://192.168.3.3:3306/test" , "root" , "12345");
...