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

问题描述

  • 编写mybatis框架的小demo时遇到了如下闹心的一幕,经过多次尝试和改正本人已成功解决该问题,但每个人遇到的问题可能会有所差异,在此为同样遭遇此问题的朋友提供一点参考,希望对您有所启发。
    MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第1张图片

解决方案

1、错误----->配置信息

  • 检查配置信息,认真核对,发现一处错误===>可长点心吧o(╥﹏╥)o
    MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第2张图片
    在这里插入图片描述
  • 修改之后再次尝试启动项目
    MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第3张图片
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)

MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第4张图片
到这里发现依旧有错误,于是根据提示做以下操作

2、错误----->修改时区

  • 查看

show variables like ‘%time_zone%’;

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

set global time_zone=’+8:00’;

MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第5张图片
再次运行项目,成功运行项目
但是这里有个小细节
MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第6张图片

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.

MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第7张图片
因此,这里还需要做一点点改动,如下:
MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第8张图片
MyBatis使用过程中的 SQLException 处理--Exception in thread “main“ org.apache.ibatis.exceptions.PE【亲测实用,可供参考】_第9张图片

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

希望对您有所帮助

✿✿ヽ(°▽°)ノ✿

你可能感兴趣的:(框架,Java,MySQL,mysql,java,intellij,idea,后端,数据库)