mybatis的常见错误

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'classId' of 'class com.zz.entity.Student' with value 'Clazz(cid=1, cname=bj_a, teacherId=1, teacher=null, students=null)' Cause: java.lang.IllegalArgumentException: argument type mismatch
### The error may exist in mapper/StudentMapper.xml
### The error may involve com.zz.dao.StudentDao.selectAllStudent
### The error occurred while handling results
### SQL: SELECT * from student,class where class_id=c_id and s_id=?
### Cause: org.apache.ibatis.reflection.ReflectionException: Could not set property 'classId' of 'class com.zz.entity.Student' with value 'Clazz(cid=1, cname=bj_a, teacherId=1, teacher=null, students=null)' Cause: java.lang.IllegalArgumentException: argument type mismatch

错误原因:参数匹配不上

解决方法:排查每个映射中的字段名是否对应
在这里插入图片描述发现字段名没有对应,进行修改,错误解决
在这里插入图片描述


Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in mapper/Clamapper
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource mapper/Clamapper

错误原因:找不到资源映射器

解决方法:
1、排查是否在配置文件中配置需要加载的 sql 映射配置文件路径。

在这里插入图片描述
发现文件类型没有标注。修改文件后缀名为.xml,修改后错误解决
在这里插入图片描述


Exception in thread "main" org.apache.ibatis.binding.BindingException: Type interface com.aaa.qy129.dao.ClazzDao is not known to the MapperRegistry.

错误原因:找不到注册文件

解决方法:排查是否在config.xml文件注册了映射文件
发现未注册文件,进行注册文件
在这里插入图片描述添加后错误解决


### Error querying database.  Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: ${jdbc.driverName}
### The error may exist in mapper/Clamapper.xml
### The error may involve com.aaa.qy129.dao.ClazzDao.findClassById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: ${jdbc.driverName}

错误原因:找不到驱动名称

解决方法:排查是否在config.xml添加db.properties文件
发现未添加db.properties文件,进行添加
在这里插入图片描述添加后错误解决


Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.aaa.qy129.dao.ClazzDao.findClassById

错误原因:找不到方法,方法名错误

解决方法:排查配置文件中的id方法名和dao接口中的方法名是否一致
发现使用错误的方法

在这里插入图片描述进行修改后,错误解决。


Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.aaa.qy129.dao.ClazzDao.findClassById'.  It's likely that neither a Result Type nor a Result Map was specified.
### The error may exist in mapper/Clamapper.xml
### The error may involve com.aaa.qy129.dao.ClazzDao.findClassById
### The error occurred while handling results
### SQL: select * from class c,teacher t,student s where c.teacher_id = t.t_id         and c.c_id =s.class_id         and c.c_id=?
### Cause: org.apache.ibatis.executor.ExecutorException: A query was run and no Result Maps were found for the Mapped Statement 'com.aaa.qy129.dao.ClazzDao.findClassById'.  It's likely that neither a Result Type nor a Result Map was specified.

错误原因:没有返回类型

解决方法:检查sql语句是否添加了resultMap
发现未添加返回类型,进行添加
在这里插入图片描述再次运行,错误解决


Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
### The error may exist in mapper/Clamapper.xml
### The error may involve com.aaa.qy129.dao.ClazzDao.findClassById
### The error occurred while executing a query
### Cause: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

错误原因:数据库账号密码错误

解决方法:在db.properties文件中设置正确的账号密码
在这里插入图片描述


Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'shop.class' doesn't exist

错误原因:找不到表

解决方法:排查是否使用了错误的数据库表
在这里插入图片描述修改正确的数据库后,错误解决


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 mapper/ClassMapper.xml
### The error may involve com.zz.dao.ClassDao.findClassById
### 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.

错误原因:数据库时区错误

解决方法:在url后面拼接serverTimezone=UTC

在这里插入图片描述添加后,错误消失。


Exception in thread "main" java.io.IOException: Could not find resource mybatis-config.xml

错误原因:没有找到文件

解决方法:检查测试类是否使用了错误的名称
在这里插入图片描述修改文件名,错误消失


记录一个奇葩bug

ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]

在这里插入图片描述

错误原因:未知原因

不影响运行结果,再次运行时就消失了,记录一下,如果有大佬知道给科普科普。
目前我知道的解决方法:重新跑一遍,就解决了

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

未来.....

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值