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. pdf ppt word office转图片 教学白板

    https://zh-cn.libreoffice.org/ http://www.imagemagick.org/script/ 首先用libreoffice将ppt转换为pdf格式,然后再用con ...

  2. Navi.Soft31.代码生成器(含下载地址)

    1系统简介 1.1功能简述 在Net软件开发过程中,大部分时间都是在编写代码,并且都是重复和冗杂的代码.比如:要实现在数据库中10个表的增删改查功能,大部分代码都是相同的,只需修改10%的代码量.此时 ...

  3. Spring Boot使用Servlet、Filter或Listener的方式

    根据官方文档说明,有两种方式可以在你的Spring Boot应用中使用Servlet.Filter或Listener. 其一:将Servlet.Filter或Listener注册成Spring Bea ...

  4. ZBar与ZXing使用后感觉

    [原]ZBar与ZXing使用后感觉(上) 2014-3-18阅读2011 评论1 最近对二维码比较感兴趣,还是那句老话,那么我就对比了一下zxing和zbar 如果对于这两个的背景不了解的话,可以看 ...

  5. JUnit4忽略(Ignore)测试实例

    这种“忽略”是指方法还没有准备好进行测试,JUnit引擎会绕过(忽略)这个方法. import org.junit.*; /** * JUnit Ignore Test * @author yiiba ...

  6. SciTE配置信息

    超强文本编辑器SciTE配置方法详细实例 转载 2006年12月28日 17:07:00 标签: 文本编辑 / 文档 / 语言 / html / python / api 32800 关于scite文 ...

  7. (源)VC助手VA破解使用指南

    一般情况下,你下载的破解版的VC助手,要么自带的有一个名为VA_X.dll的文件,要么是有一个可运行的破解程序,根据不同的情况进行如下操作,只要你下载的安装文件没有问题,就能正确打上破解补丁.网上有一 ...

  8. Erlang HTTP client:ibrowse

    ibrowse: https://github.com/cmullaparthi/ibrowse

  9. Enhance基本例子

    太晚了,有些东西没有补充,回头再补上. 先上Demo 1.要执行的方法 package enhancerTest; /** * Created by LiuSuSu on 2017/3/26. */ ...

  10. [CentOS]使用Jenkins配置Git+Maven的自动化构建

    背景 最近安装Jenkins,参照网上的各种资料进行尝试,折腾了好久,但是查找了这么多资料,相似度在90%以上!!!,相同的安装过程,测试了几台机器,未曾成功,不得不感慨自己能力有限,最终慢慢摸索,形 ...