java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼异常解决

今天写测试类出现一些异常,代码连接数据库查询测试无法通过,此都是和数据库的配置有关,在此也是总结一下。

出现的第一个异常

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

意思是 mysqljdbc . driver被弃用了新的驱动类是“com.mysql.cjdbc.driver”。驱动程序通过SPI自动注册,而手动加载类通常是不必要的,解决方案如下:

把 配 置 文 件 中 的 的 c o m . m y s q l . j d b c . D r i v e r 改 为 c o m . m y s q l . c j . j d b c . D r i v e r 即 可 \color{red}{把配置文件中的的com.mysql.jdbc.Driver 改为com.mysql.cj.jdbc.Driver 即可} com.mysql.jdbc.Drivercom.mysql.cj.jdbc.Driver

本以为修改之后测试能够通过,嗯哼,接下来出现了两一个异常

出现的第二个异常

j a v a . s q l . S Q L E x c e p t i o n : T h e s e r v e r t i m e z o n e v a l u e ′ O ¨ Ð ¹ u ˊ ± e ^ × ¼ E ^ ± ¼ a ¨ ′ ′ i s u n r e c o g n i z e d o r r e p r e s e n t s m o r e t h a n o n e t i m e \color{red}{java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä''is unrecognized or represents more than one time } java.sql.SQLException:TheservertimezonevalueO¨Ð¹uˊ±e^×¼E^±¼a¨isunrecognizedorrepresentsmorethanonetime

提示系统时区出现错误,可以在mysql中执行命令:
set global time_zone=’+8:00’
或者在数据库驱动的url后加上serverTimezone=UTC参数

写代码的时候要注意,如果该参数是‘?’后的第一个,即

jdbc:mysql://localhost:3306/exam?serverTimezone=UTC
是没有问题的,但如果不是第一个,即

jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&serverTimezone=UTC

这种写法是会报错的,会提示The reference to entity “serverTimezone” must end with the ‘;’ delimiter.
运行后控制台也会出现
对实体 “serverTimezone” 的引用必须以 ‘;’ 分隔符结尾。
的错误提示。
将代码改为

jdbc:mysql://localhost:3306/exam?characterEncoding=utf8&serverTimezone=UTC
即可。在xml的配置文件中 ;要用 & 代替。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值