使用mybatis报错

1

Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. 
Cause: java.lang.ClassNotFoundException: Cannot find class: com.mysql.cj.jdbc

将mybatis-config.xml文件中
<property name = "driver" value="com.mysql.cj.jdbc"
更改为
<property name = "driver" value="com.mysql.cj.jdbc.Driver"
解决

2

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 specific time zone value if you want to utilize time zone support.

时区问题
将一开始的数据库的URL
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false"/>
改为
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=false&amp;serverTimezone=UTC"/>
解决

3没有输出查询结果1,结果为空

[DEBUG] 15:00:25.580 [main] test.selectAll - ==>  Preparing: select * from tb_user; 
[DEBUG] 15:00:25.612 [main] test.selectAll - ==> Parameters:  
[DEBUG] 15:00:25.634 [main] test.selectAll - <==      Total: 0 
[]//为空

嗷,搞半天,发现原来是我数据库表里没数据,睿智哦
添加数据后,可以成功查询出

[DEBUG] 15:03:27.666 [main] test.selectAll - ==> Parameters:  
[DEBUG] 15:03:27.699 [main] test.selectAll - <==      Total: 3 
[User{id=1, username='zhangsan', password='123', gender='男', addr='北京'}, User{id=2, username='李四', password='234', gender='女', addr='天津'}, User{id=3, username='王五', password='11', gender='男', addr='西安'}]

posted @ 2022-07-08 15:06  Crazy_chicken  阅读(68)  评论(0)    收藏  举报