【踩坑】JDBC 报错 The server time zone value '' ...

前言

运行JDBC代码后,报错:Exception in thread "main" 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.

原因

  • 没有正确设置时区

问题解决

  • jdbc:?后增加配置serverTimezone=UTC,多个配置用&隔开

UTC为全球标准时间

1
jdbc:mysql://localhost:3306/xscj?serverTimezone=UTC

完成

参考文献

CSDN——喵主子