jdbc连接报错CannotGetJdbcConnectionException

使用jdbc连接window环境下的MySQL报错:
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 specifc time zone value if you want to utilize time zone support.

主要是window环境下的时区设置错误。更改时区信息即可。

1、更改数据库时区

连接数据库:使用命令查看时区信息
show variables like ‘%time_zone%’;
在这里插入图片描述
更改数据库的时间为东八区:
set global time_zone=’+8:00’;
在这里插入图片描述

2、更改url连接

将数据库连接的url添加参数:
jdbc:mysql://127.0.0.1:3306/jd?serverTimezone=GMT%2B8

总结

window环境下安装mysql需要设置当前的时区为东八区。

Logo

更多推荐