错误信息

今天在复习 JavaEE 相关内容的时候,遇到报错

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.

然后发现他的driver也改成com.mysql.cj.jdbc.Driver

原因

​ 驱动包版本:mysql-connector-java-8.0.18.jar

​ 后来在查资料后发现数据库安装时默认为英语,是0:00时区,但是用以前旧版本的MySql jdbc 驱动都不会让你设置时区,新版就需要了。。。。

解决方法

将连接数据库的url加上,UTC(世界均衡时间)参数,或者GMT(格林尼治时间),如下:

jdbc:mysql://localhost:3306/demo?serverTimezone=UTC
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=UTC
jdbc:mysql://localhost:3306/demo?serverTimezone=GMT
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=GMT

不过后来测试发现,这个时间比北京时间早8个小时,所以使用北京时间如下:

jdbc:mysql://localhost:3306/demo?serverTimezone=GMT%2B8
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=GMT%2B8

一只大大怪

相关文章:

  • 2023-02-27
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
猜你喜欢
  • 2022-02-10
  • 2021-09-27
  • 2022-12-23
  • 2021-06-23
  • 2021-10-18
  • 2021-09-28
  • 2022-12-23
相关资源
相似解决方案