It is impossible for some reason to connect to the database. Catch catches an exception.

public class Main { private static final String URL = "jdbc:mysql://localhost:3306/mydbtest?useSSL=false"; private static final String LOGIN = "root"; private static final String PASSWORD = "root"; public static void main(String[] args) { Connection connection = null; try { connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydbtest?useSSL=false", "root", "root"); if(!connection.isClosed()){ System.out.println("TRUE"); } } catch (SQLException e) { System.err.println("Невозможно подлючиться к БД!"); } } } 

enter image description here

  • 2
    Could you write e.printStackTrace ()? - Qertu Uerty
  • java version? jdbc driver version? - Vadim
  • DriverManager.registerDriver (new com.mysql.cj.jdbc.Driver ()); - Vadim
  • @ Vadim it does not help. - anton.rynkovoy
  • @QertuUerty Here is the error. - anton.rynkovoy

1 answer 1

You have a problem in that the database sends the time zone in Russian. At the same time, you probably also have a problem with the encoding.

In order to "fix" an error with a time zone (using the wrong time at the same time is suitable for local development), you can add serverTimezone = UTC as a JDBC parameter. It is also possible to change the MySQL and JDBC encoding to the same one.

Another option is to change the time zone of MySQL itself using this SQL query (change the time to UTC + 3, Moscow. Another option is "Europe / Moscow"):

 SET time_zone = "+3:00" 
  • @Roman Fixed, thanks. - Qertu Uerty