Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: The server time zone...

IDEA中maven项目使用JFinal框架链接本地数据库时报错:

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.

翻译后:

服务器的时区 value ‘?й? ? ? ? ? ? ?’ 未被识别或代表多个时区。您必须配置服务器或JDBC驱动程序(通过serverTimezone配置属性),如果您想要利用时区支持,则需要使用更特殊的时区值。

图片:



其实这个不是复杂的问题, 其实是为了使MySQL JDBC驱动程序与UTC时区配合使用,必须在连接字符串中明确指定serverTimezone。

为URL添加参数:

?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

也就是:

jdbc:mysql://localhost:3306/lovewhf?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC

在这里边明确指定serverTimezone
在运行程序就不会报错啦!

猜你喜欢

转载自blog.csdn.net/qq784515681/article/details/79544951