问题描述
- 编写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!]
希望对您有所帮助
✿✿ヽ(°▽°)ノ✿