开始学习Mybatis踩的第一坑

1、第一次学习Mybatis就报错:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class:com.mysql.jdbc.Driver
### The error may exist in sqlmap/User.xml
### The error may involve test.findUserById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class:com.mysql.jdbc.Driver 

才开始看视频,就遇到了这个问题,也是百度查了很久才发现,原来是Mysql的JDBC驱动版本的问题,因为自己安装的是Mysql-5.7.24,所以在导依赖的时候想当然的就是直接使用5.7.24版本的依赖,但是:

mysql 5.7 可以使用8.0版本的驱动,使用5.1版本的驱动也可以,但是就是不能使用5.55.65.7的驱动。
MySQL Connectors 官方文档 上面只有version8.0和version5.1两个版本的文档
version8.0文档上有说明:Connector/J 8.0 provides compatibility with all the functionality of MySQL 5.5, 5.6, 5.7, and 8.0表示兼容。

5.7版本没有自身版本的驱动,只有5.1或者8.0版本的,所以最后我是使用8.0版本的驱动,成功解决这个问题。

2、改完上一个错误后,紧接着就出现下面的报错(宝宝苦呀):

### 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/nscrl/Dao/IUserDao.xml
### The error may involve com.nscrl.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.

使用mybatis连接mysql8.0社区版时出现了这个异常信息,因为mysql默认的时区和本地时区不一致导致的
解决方法:连接mysql时指定时区为UTC

jdbc:mysql://localhost:3306/mybatis?serverTimezone=UTC

猜你喜欢

转载自blog.csdn.net/zzlove1234567890/article/details/102904255