java.sql.SQLException: The server time zone value 连接mybatis 时候的错误

本文详细解释了如何解决在连接MySQL数据库时遇到的时区配置错误,通过正确设置URL参数serverTimezone来指定时区,同时介绍了如何更新过时的Driver类名以及MyBatis中下划线转驼峰的配置。
摘要由CSDN通过智能技术生成

具体报错如下:

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.

报错信息很明白,你需要配置一个时区.
我原来的jdbc:

spring.datasource.url=jdbc:mysql://localhost:3306/test?

我加上时区后的jdbc和编码格式的jdbc:

spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&characterEncoding=utf8

查询成功:
在这里插入图片描述

题外话说一句:
在这里插入图片描述

  • 如果使用spring.datasource.driver-class-name=com.mysql.jdbc.Driver过时,可以使用spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  • mybatis.configuration.map-underscore-to-camel-case=true 意思是把数据库里面的下划线格式book_name,映射成bookName这种驼峰格式.名称很清楚map(转换,映射),underscore(下划线),camel(骆驼).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值