添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

用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>
) <- 删除
数据库疑难杂症 java . sql . SQL SyntaxErrorException: You have an error in your SQL syntax; check the manual that correspo nd s to your My SQL server version for the right syntax to use near ‘order’ at line 1 数据库报错如下: Error querying database. Ca use : java . sql . SQL SyntaxErrorException: You have an error in your SQL mybatis Ca use : java . sql . SQLException : Opera nd should contain 1 column (s).大体表示一列也没拿到 错误原因归结于写 mybatis 语法错误。 首先看看本人的使用 mybatis 批量插入my sql 的 xml &lt;insert id="InsertSJSBatch" parameterType=" java .util.Lis... MyBatis 遇到问题:Error querying database. Ca use : java . sql . SQLException : Opera nd should contain 1 column (s) java . sql . SQLException : Opera nd should contain 1 column (s) java . sql . SQLException : You ca n’t specify target table ‘city’ for update in FROM cla use ** 今天在搞jdbc时,写 sql 语句,需要对数据先查询然后再修改,我的语句如... SQL 执行delete in条件语句时,出现“[Err] 1241 - Opera nd should contain 1 column (s)”错误,在Eclipse中也报了如下错误:### Error updating database. Ca use : java . sql . SQLException : Opera nd should contain 1 column (s)### The error m... SQL : SELECT * from items WHERE name LIKE (’%’,?,’%’) Ca use : java . sql . SQLException : Opera nd should contain 1 column (s) ; bad SQL grammar []; nested exception is java . sql . SQLException : Opera nd should co... <br />原因:权限采用联合主键,默认daoSupport的分页方法时不采用联合主键的, select count(o) from POJO o这句会出现问题导致这个 异常 。<br />修改方案:当前类重写分页方法,将" select count(o) from POJO o" count()中的o改为出其主键外的任一属性(eg:o.name)既可。<br />exception stack: <br /> java x.persistence.PersistenceException: org.hibernate 检查提示错误信息中的 SQL 语句是否有细节上的错误 说明白点就是粗心大意写错了 SQL 语句导致语法错误,这种错误都是不容易发现的小错误,比如:查询语句查询的内容本来不用写括号的,你多写了括号。或者多一个括号,多一个“ 少一个”等! Error querying database. Ca use : java . sql . SQLException : Opera nd should contain 1 column (s) [ERROR:]2015-05-05 15:48:55,847 [ 异常 拦截] org.hibernate.exception.DataException: error executing work at org.hibernate.exception.internal. SQL StateConversio nD elegate.convert( SQL StateConversion... mybatis 配置: &lt; select id="queryDubboConfig" parameterType="map" resultMap="DubboConfigDO"&gt; SELECT (app_name, project_name, project_branch, interface_name, dubbo_app_name, dubbo_int...