MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】

问题描述

  • 编写mybatis框架的小demo时遇到了如下闹心的一幕,经过多次尝试和改正本人已成功解决该问题,但每个人遇到的问题可能会有所差异,在此为同样遭遇此问题的朋友提供一点参考,希望对您有所启发。
    在这里插入图片描述

解决方案

1、错误----->配置信息
  • 检查配置信息,认真核对,发现一处错误===>可长点心吧o(╥﹏╥)o
    在这里插入图片描述
    在这里插入图片描述
  • 修改之后再次尝试启动项目
    在这里插入图片描述
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 com/c_being/dao/IUserDao.xml
### The error may involve com.c_being.dao.IUserDao.findAll
### 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.binding.MapperMethod.executeForMany(MapperMethod.java:147)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80)
	at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:144)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85)
	at com.sun.proxy.$Proxy0.findAll(Unknown Source)

在这里插入图片描述
到这里发现依旧有错误,于是根据提示做以下操作

2、错误----->修改时区
  • 查看

show variables like ‘%time_zone%’;

  • 修改(因为中国处在东八区,因此设置为+8:00)

set global time_zone=‘+8:00’;

在这里插入图片描述
再次运行项目,成功运行项目
但是这里有个小细节
在这里插入图片描述

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.

在这里插入图片描述
因此,这里还需要做一点点改动,如下:
在这里插入图片描述
在这里插入图片描述

(o゜▽゜)o☆[BINGO!]

希望对您有所帮助

✿✿ヽ(°▽°)ノ✿

:: 更多内容 ::

> 开发过程中踩坑经验记录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值