org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.apache.

文章描述了一个在使用MyBatis时遇到的异常情况,具体是尝试将字符串转换为整数时抛出了ClassCastException。问题可能存在于UserMapper.xml文件中的参数映射配置,错误涉及到了添加用户的方法addUser。解决方法包括检查parameterType的设置,可能是将参数类型从int改为com.swust.yhc.pojo.User,或者修正name属性的映射类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘name’, mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

The error may exist in com/swust/yhc/dao/UserMapper.xml

The error may involve com.swust.yhc.dao.UserMapper.addUser-Inline

The error occurred while setting parameters

SQL: insert into mybatis.user(id, name, pwd) VALUES (?,?,?);

Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property=‘name’, mode=IN, javaType=class java.lang.Integer, jdbcType=null, numericScale=null, resultMapId=‘null’, jdbcTypeName=‘null’, expression=‘null’}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #2 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

在这里插入图片描述
错误原因:select 标签里用insert语句 不用提交,但没返回值
所以直接删除parameterType="int"即可
或者

parameterType="com.swust.yhc.pojo.User"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值