Java and Mysql - Error - Timezone

Asked

Viewed 1,041 times

2

I try to connect with Mysql, with the code below. I don’t use Hibernate or anything. It is just to connect to the database and run a simple SQL clause. I get the error that is below.

I see you have some questions with answers here, but I confess I don’t understand.

Error message:

java.sql.Sqlexception: The server time zone value 'Europe Standard Time Ocident' 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.

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();
        }    
    }    
}
  • I added this to my comic book URL and it worked: ? useSSL=false&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

1 answer

3

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

Will stay like this:

DriverManager.getConnection("jdbc:mysql://localhost:3306/mondovino?useTimezone=true&serverTimezone=UTC", "root", "senha");
  • Perfetto. Niente come parlare con chi sa cosa si deve fare. Certinho. Valeu.

  • @Alano, mark the answer as correct. This will indicate to others that the answer is correct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.