1、调用getConnection()连接数据库就会报出异常
DriverManager.getConnection(SQL_URL, SQL_USERNAME, SQL_PASSWORD);
通过控制台打印看到,每次调用这个函数就会发生异常。
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.
网上查了一下,说是安装mysql 设置的时区不正确导致,重新设置mysql 的时区,如下
mysql> set global time_zone='+8:00';
这样貌似问题可以解决了,但是数据库如果重启了之后,又会出现一样的错误。可以通过另外一种方式来解决这个错误,在连接数据库的url中设置时区
private static final String SQL_URL = "jdbc:mysql://localhost:3306/db_test;