JDBC报连接数据库时因时区问题报错

JDBC报连接数据库时因时区问题报错:

Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is 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 specific time zone value if you want to utilize time zone support.
The error may exist in file

报错原因:

新版MySQL通过JDBC连接时需要加时区

解决方案:

在连接数据库的URL后面加上

&serverTimezone=UTC

例如:

jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC

猜你喜欢

转载自blog.csdn.net/weixin_43482906/article/details/112782856
今日推荐