2
votes

Currently in Europe the timezone was changed and now its one hour more. For some reason this broke my script, and I cant connect to my mysql database.

I tried restarting, stopping and starting mysql server, even restarting eclipse. None of this works.

    public static Connection getConnection() throws Exception{
        try {
            String driver = "com.mysql.cj.jdbc.Driver";
            String url = "jdbc:mysql://localhost:3306/db";
            String username = "root";
            String password = "***";
            Class.forName(driver);

            Connection DB = DriverManager.getConnection(url, username, password);
            System.out.println("Connected to Database");        
            return DB;
        } catch(Exception e) {System.out.println(e);        
        }

        return null;
    }

This worked before the time change, now I get this error

java.sql.SQLException: The server time zone value 'CEST' 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.

2

2 Answers

1
votes

This can be fixed on the server-side with an explicit timezone setting in my.cnf. If your timezone is for instance, Europe/Berlin:

[mysqld]
default-time-zone = Europe/Berlin
0
votes

try this : String url = "jdbc:mysql://localhost:3306/db?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";