spring JdbcTemplate  queryForList 出错

Incorrect column count: expected 1, actual 5

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright 蕃薯耀 2017年7月10日

http://www.cnblogs.com/fanshuyao/

一、问题描述:

查询时使用JdbcTemplate 中的queryForList发生错误,如下:

查询方法如下:

  1. jdbcTemplate.queryForList(selectSql.toString(), entityClass)

查询sql如下:

  1. select * from test where 1=1 order by create_time desc limit 0,10

错误如下:

  1. Incorrect column count: expected 1, actual 5

二、解决方案:

1、上面错误的原因是,查询返回的结果列期望为1,但实际返回的是5列,因为test表中有5个字段,故返回5列。而这个方法参数的解释是这样的:

  1. Parameters:
  2. sql SQL query to execute
  3. elementType the required type of element in the result list (for example, Integer.class)

就是第2个参数在网上说只能是简单类型String或Integer。

2、使用query查询

  1. jdbcTemplate.query(selectSql.toString(), rowMapper)

但多了一个参数rowMapper,这个参数需要定义为:

  1. @SuppressWarnings("unused")
  2. private BeanPropertyRowMapper<T> rowMapper = new BeanPropertyRowMapper<T>(entityClass){
  3. @Override
  4. protected void initBeanWrapper(BeanWrapper bw) {
  5. super.initBeanWrapper(bw);
  6. }
  7. };

具体的作用就是进入查询结果转换成实体。

到这步也就解决问题了。

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

©Copyright 蕃薯耀 2017年7月10日

http://www.cnblogs.com/fanshuyao/

Incorrect column count: expected 1, actual 5,JdbcTemplate queryForList 出错的更多相关文章

  1. 使用JdbcTemplate报 Incorrect column count: expected 1, actual 5错误解决

    Incorrect column count: expected 1, actual 5 在使用jdbc的querForObject queryForList的时候,出现Incorrect colum ...

  2. Incorrect column count: expected 1, actual 5

    在使用jdbc的querForObject queryForList的时候,出现Incorrect column count: expected 1, actual 5 比如 String sql = ...

  3. Incorrect column count: expected 1, actual 2

    List<Long> idList = queryForList("ass.pageQuery_sgIds", paramMap, Long.class); 报错:In ...

  4. Incorrect column count: expected 1, actual 6

    JdbcTemplate使用时出现了一些问题: 解决办法:

  5. QueryError:Incorrect result size: expected 1, actual 0

    1.错误描述 QueryError:Incorrect result size: expected 1, actual 0 2.错误原因 3.解决办法

  6. ORA-00001:unique constraint violated 以及 Incorrect result size: expected 1, actual 0

    往数据库中插入数据时报错:   www.2cto.com   ORA-00001: unique constraint (IDX_CARTON_HEADER)violated.   即往CARTON_ ...

  7. (后端)org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1,actual 0

    两种方案: 用queryForList方法替换queryForObject或者queryForMap,因为这两个方法必须要有值,不能为空. 把这个异常捕获,用try/catch. 这个查询的结果是nu ...

  8. 调用 jdbcTemplate.queryForList 时出现错误 spring-org.springframework.jdbc.IncorrectResultSetColumnCountException

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  9. Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50096, now running 50173.

    IDEA链接mysql提示 Column count of mysql.proc is wrong. Expected 20, found 16. Created with MySQL 50096, ...

随机推荐

  1. 《VS2010/MFC编程入门教程》——读书笔记

    推荐两个比较好的学习网站:http://v.dxsbb.com/jisuanji/555/ http://www.jizhuomi.com/software/257.html MFC全称Microso ...

  2. Sublime Text3工具的安装、破解、VIM功能vintage插件教程

    1.安装Sublime Text 3  下载安装:http://www.sublimetext.com/3 Package Control安装:https://sublime.wbond.net/in ...

  3. JSP之应用Servlet过滤器进行身份验证

    1.Servlet过滤器的作用描述(1)在HttpServletRequest到达Servlet 之前,拦截客户的HttpServletRequest. 根据需要检查HttpServletReques ...

  4. JSP之response对象使用

    1.使用response对象实现重定向 response.sendRedirect("http://www.cnblogs.com"); 2.使用response对象刷新页面 每隔 ...

  5. python 读写二进制文件实例

    本程序,首先写入一个矩阵到二进制文件中,然后读取二进制文件恢复到另外一个矩阵中. #coding:utf--8 #https://www.cnblogs.com/cmnz/p/6986979.html ...

  6. 第三百三十五节,web爬虫讲解2—Scrapy框架爬虫—豆瓣登录与利用打码接口实现自动识别验证码

    第三百三十五节,web爬虫讲解2—Scrapy框架爬虫—豆瓣登录与利用打码接口实现自动识别验证码 打码接口文件 # -*- coding: cp936 -*- import sys import os ...

  7. python写的读取json配置文件

    配置文件默认为conf.json 使用函数set完成追回配置项. 使用load或取配置项. 代码如下: #!/usr/bin/env python3 # -*- coding: utf-8 -*- ' ...

  8. 转载: IM系统架构设计之浅见

    出处:http://yaocoder.blog.51cto.com/2668309/1412029 背 景:除去大名鼎鼎的QQ这款即时聊天工具,还有许多细分行业的IM,比如淘宝阿里旺旺.网易泡泡.YY ...

  9. EayRadius 于 2013-7-19 进行体验度更新,增加用户体验度

    EasyRadius于2013-7-19进行更新,此次更新并没有更新通讯接口,通讯接口将统一更新,包括对其他路由的支持 下面我将主要更新的地方向大家描述一下 如果你有疑问或者建议,可以致电137799 ...

  10. Throwable vs Exception

    Throwable中的Error是不需要程序处理的. Exception是需要处理的.