本文主要是介绍jdbc连接报错CannotGetJdbcConnectionException,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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需要设置当前的时区为东八区。
这篇关于jdbc连接报错CannotGetJdbcConnectionException的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!