jdbc连接报错-time zone相关
报错信息:
java.sql.SQLException: The server time zone value 'EDT' 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.
问题排查:
连接mysql库,执行sql:select CURRENT_TIMESTAMP 结果:2020-04-09 06:08:50;而当前北京时间是2020-04-09 18:08:50;
报错原因:
数据库使用的时区是‘EDT’,与系统时区差异
解决办法:
修改数据库配置信息,在jdbc连接的url后面加上serverTimezone=GMT
例如:jdbc:mysql://127.0.0.1:3306/db?user=userName&password=passWord&useUnicode=true&serverTimezone=GMT&characterEncoding=utf-8
扩展说明:
UTC:协调世界时,又称世界统一时间、世界标准时间、国际协调时间。由于英文(CUT)和法文(TUC)的缩写不同,作为妥协,简称UTC。协调世界时是以原子时秒长为基础,在时刻上尽量接近于世界时的一种时间计量系统
GMT时间:格林尼治标准时间,是UTC+0时区的知名名称之一,比UTC(协调世界时)提前0个小时,它被用作标准时间
EDT 时间:北美东部夏令时间, 是UTC-4时区,比UTC(协调世界时)落后4个小时与UTC的时间偏差可写为-04:00,它被用作夏令时
CST时间:中国标准时间。在时区划分上,属东八区,比UTC(协调世界时)早8小时,记为UTC+8
浙公网安备 33010602011771号