MyBatis Cause: java.sql.SQLException: Operand should contain 1 column(s) 异常处理
Posted FserSuN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBatis Cause: java.sql.SQLException: Operand should contain 1 column(s) 异常处理相关的知识,希望对你有一定的参考价值。
用mybatis foreach出现异常Operand should contain 1 column(s)
<select id="selectByCreditIdList" resultMap="BaseResultMap">
SELECT * FROM table
WHERE id IN (
<foreach collection="creditIdList" item="cid" index="index" open="(" close=")" separator=",">
#cid
</foreach>
)
</select>
暴出的异常如下。
Error querying database. Cause: java.sql.SQLException: Operand should contain 1 column(s)
### The error may exist in com/fengdai/finance/dao/CreditBillCycleDao.xml
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT * FROM credit_bill_cycle WHERE ( id IN ( ( ? , ? ) ) )
### Cause: java.sql.SQLException: Operand should contain 1 column(s)
发现生成IN 后跟随的列表是一个( ? , ? ) ,因此产生Operand should contain 1 column(s)异常。删除MyBatis sql映射文件中的外围括号,问题解决。
( <-删除
<foreach collection="creditIdList" item="cid" index="index" open="(" close=")" separator=",">
#cid
</foreach>
) <- 删除
以上是关于MyBatis Cause: java.sql.SQLException: Operand should contain 1 column(s) 异常处理的主要内容,如果未能解决你的问题,请参考以下文章
Cause: java. lang.InstantiationException: tk.mybatis.mapper.provider.base.BaseInsertProvider
Mybatis报错 Error querying database. Cause: org.apache.ibatis.reflection.ReflectionException: Error
Mybatis Error attempting to get column 'xxx' from result set. Cause: java.sql.SQLDataExcepti
Mybatis Error attempting to get column 'xxx' from result set. Cause: java.sql.SQLDataExcepti
MyBatis Cause: java.sql.SQLException: Operand should contain 1 column(s) 异常处理
mybatis报错Error attempting to get column ‘id‘ from result set. Cause: org.postgresql.util.PSQLExcept