【mybatis】Fix:Cause: java.sql.SQLDataException: Cannot determine value type from string ‘tom‘

报错信息如下:

Opening JDBC Connection
Created connection 1988644427.
Setting autocommit to false on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
==>  Preparing: select emp_id as empId, emp_name as empName, emp_salary as empSalary from t_emp where emp_id=?
==> Parameters: 1(Integer)
<==    Columns: empId, empName, empSalary
<==        Row: 1, tom, 999.99
Resetting autocommit to true on JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
Closing JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@76884e4b]
Returned connection 1988644427 to pool.

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'empName' from result set.  Cause: java.sql.SQLDataException: Cannot determine value type from string 'tom'
### The error may exist in mappers/EmployeeMapper.xml
### The error may involve com.boyan.mapper.EmployeeMapper.selectEmpById
### The error occurred while handling results
### SQL: select emp_id as empId, emp_name as empName, emp_salary as empSalary from t_emp where emp_id=?
### Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'empName' from result set.  Cause: java.sql.SQLDataException: Cannot determine value type from string 'tom'

	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)

解决思路:通过查看控制台输出日志信息,已经查找到正确内容,因此无法将查找到的数据和相应类型对应,问题应该是出现在测试返回路径中的文件中,检查过程文件中定义均正确,但测试依然存在问题。问题报错又是无法对应值的类型,所以去检查 pojo 类,再经查询发现 “MyBatis 需要默认构造函数来实例化对象”。所以发现问题所在,添加无参数构造函数后,✅测试成功,问题解决。

问题定位:pojo.Employee03.java 缺少无参数构造函数(错误原因:⚠️ MyBatis 需要默认构造函数来实例化对象)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值