在尝试执行MyBatis查询时,遇到了问题Loading class com.mysql.jdbc.Driver‘. This is deprecated. The new driver class

执行遇到的错误

在学习javaweb尝试MyBatis查询时,执行遇到错误

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: 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.
### The error may exist in UserMapper.xml
### The error may involve UserMapper.selectAll
### The error occurred while executing a query
### Cause: 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.
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:149)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:135)
    at com.blog.MyBatisDemo.main(MyBatisDemo.java:22)

错误原因

1、错误一

正在加载的com.mysql.jdbc.Driver类已经过时,应该使用新的驱动类com.mysql.cj.jdbc.Driver。这通常是因为你的代码或配置文件中直接指定了旧的驱动类名。解决方法是更新你的代码或配置文件,使用新的驱动类名。

2、错误二

错误信息显示“服务器时区值无法识别或代表多个时区”,这是由于MySQL服务器和JDBC驱动程序之间时区配置不匹配导致的。具体错误信息为:“The server time zone value '�й���׼ʱ��' is unrecognized...”。解决这个问题的方法是在连接字符串中明确指定时区。你需要在数据库连接URL中添加serverTimezone参数,设置为你期望的具体时区,例如设置为UTC时区

解决办法

1、针对错误一

更新驱动类名:确保你的代码或配置文件中使用的是

com.mysql.cj.jdbc.Driver

作为驱动类名,替代旧的com.mysql.jdbc.Driver

2、针对错误二

配置时区:在数据库连接URL中添加serverTimezone参数,确保时区正确配置。

要在 JDBC 连接 URL 中配置时区,需要添加 serverTimezone 参数

<property name="url" value="jdbc:mysql:///mybatis?useSSL=false&amp;serverTimezone=UTC"/>

成功执行

  • 20
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值