Java and MySQL - Error - Timezone

1

I try to connect to MySQL with the code below. I do not use Hibernate, or anything. It's just to connect to the bank and run a simple SQL clause. I get the error below.

I've seen some questions with answers here, but I confess I did not understand.

Error message:

  

java.sql.SQLException: The time zone value 'Western Europe Standard Time' 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 use time zone support.

Code:

import java.sql.*;

public class ConnectMySql {
    public static void main(String[] args) {
        try {
            // Estabelece a conexão
            Connection cnx = DriverManager.getConnection("jdbc:mysql://localhost:3306/mondovino", "root", "senha");

            // Cria um Statement
            Statement stmt = cnx.createStatement();

            // Executa a query
            ResultSet rset = stmt.executeQuery("seletc * from paese"); 

            // Navega no result set
            while (rset.next()) {
                System.out.println("Pais " + rset.getString("fips") + " -> " + rset.getString("nomepaese"));
            }
        }
        catch(Exception e) {
            e.printStackTrace();
        }    
    }    
}
    
asked by anonymous 28.12.2018 / 19:48

1 answer

1

Try to add these parameters to your url: useTimezone=true&serverTimezone=UTC

It will look like this:

DriverManager.getConnection("jdbc:mysql://localhost:3306/mondovino?useTimezone=true&serverTimezone=UTC", "root", "senha");
    
28.12.2018 / 19:52