@P_Alexander
First head

Проблема с подключением к базе данных?

У меня фулл версия IntelJIDEA делаю подключение к базе данных, приписал пароли скачал драйвер в настройках, сделал проверочный тест, все нормально к базе подключился(MySQL)
Далее пишу банальный код:
public class MAin {
private static String url = "jdbc:mysql://localhost:3306/warmstar";
private static String user = "root";
private static String pas = "++++";
public static void main(String[] args) {
try{
try {
Class.forName("com.mysql.jdbc.Driver");

}catch (ClassNotFoundException e){
e.printStackTrace();
}
try(Connection connection = DriverManager.getConnection(url, user, pas); Statement statement = connection.createStatement()){
System.out.println(connection.isClosed());
}catch (SQLException e){
e.printStackTrace();
}
}
}
И вот вывод в консоль:
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Wed Dec 06 17:56:57 EET 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
java.sql.SQLException: The server time zone value 'Ôèíëÿíäèÿ (çèìà)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:81)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:55)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:65)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:70)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:853)
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:440)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:221)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at pac.MAin.main(MAin.java:21)
Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone value 'Ôèíëÿíäèÿ (çèìà)' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:54)
at com.mysql.cj.core.exceptions.ExceptionFactory.createException(ExceptionFactory.java:73)
at com.mysql.cj.core.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:118)
at com.mysql.cj.mysqla.MysqlaSession.configureTimezone(MysqlaSession.java:360)
at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1434)
at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:986)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:843)
... 6 more
Что это такое и как его решить, гуглил не помогло...
  • Вопрос задан
  • 6336 просмотров
Решения вопроса 1
azerphoenix
@azerphoenix Куратор тега Java
Java Software Engineer
А если что-то типа такого написать не прокатит? У меня на Intellij Idea 2017.3 && jdbs mysql connector 5.1.45 работает
private static final String URL = "jdbc:mysql://localhost:3306/dbname";
    private static final String USERNAME = "bla-bla";
    private static final String PASSWORD = "bla-bla";

public static void main(String[] args) {
Connection connection;
        try {
            Driver driver = new FabricMySQLDriver();
            DriverManager.registerDriver(driver);

            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

            if (!connection.isClosed()) {
                System.out.println("Соединение с БД установлено");
            }
        }catch (SQLException e) {
            System.out.println("Не удалось загрузить класс драйвера");
        }
}


Или же попробуйте вместо Class.forName("com.mysql.jdbc.Driver"); указать
Class.forName("com.mysql.cj.jdbc.Driver");
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы