Ошибка подключения к MySQL серверу "java.sql.SQLNonTransientConnectionException"

Я запустил сервер, пытаюсь подключиться к нему, чтобы достать данные из таблицы, но вылетает ошибка коннекта. Хотя при помощи DB Browser'а подключиться всё таки удаётся. скрин из явы.

public class JavaToMySQL {

public static void main(String args[]) {
    try {
        Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();

        try (Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db/root/password")){
             Statement stmt  = con.createStatement();
             ResultSet   rs = stmt.executeQuery("SELECT * FROM db.books;");
             while (rs.next()) {

            int id = rs.getInt("id");
            String author= rs.getString("author");
            System.out.printf("%d. %s - %d \n", id , author);
        }
    }
}

    catch (Exception e) {
        System.out.println(e);

    }
}

}

После запуска

java.sql.SQLNonTransientConnectionException: Cannot connect to MySQL server on localhost:3 306.

Make sure that there is a MySQL server running on the machine/port you are trying to connect to and that the machine this software is running on is able to connect to this host/port (i.e. not firewalled). Also make sure that the server has not been started with the --skip-networking flag.

Process finished with exit code 0

Может я что-то неверно задал в MySQL? мускле скрин


Ответы (0 шт):