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. 微信小程序——加入购物车弹层

    对于网上商城,加入购物车是一个必备功能了.俺今天就来说下在微信小程序里如何造一个购物车弹层. 先上图: 主要用到的微信API:wx.createAnimation(OBJECT) 说下思路: 1.wx ...

  2. Java Set List Map

    对JAVA的集合的理解是想对于数组 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型) JAVA集合可以存储和操作数目不固定的一组数据. 所有的JAVA集合都位于 java. ...

  3. Android图片二进制与Bitmap、Drawable之间的转换

    Android图片二进制与Bitmap.Drawable之间的转换 Java代码  public byte[] getBitmapByte(Bitmap bitmap){      ByteArray ...

  4. [转]Android开源测试框架学习

    近期因工作需要,分析了一些Android的测试框架,在这也分享下整理完的资料. Android测试大致分三大块: 代码层测试 用户操作模拟,功能测试 安装部署及稳定性测试 代码层测试 对于一般java ...

  5. FTP服务器的配置与实现

    一.准备工作 实验目的:完成FTP服务器的配置,并能熟练操作. 环境搭建: 虚拟机  vmware workstation windows2003镜像文件 Serv-U 主机 二.步骤 1,在虚拟机中 ...

  6. Mybatis系列(三):Mybatis实现关联表查询

    原文链接:http://www.cnblogs.com/xdp-gacl/p/4264440.html 一.一对一关联 1.1.提出需求 根据班级id查询班级信息(带老师的信息) 1.2.创建表和数据 ...

  7. C#基础 ---------------单利模式

    一.引言 最近在设计模式的一些内容,主要的参考书籍是<Head First 设计模式>,同时在学习过程中也查看了很多博客园中关于设计模式的一些文章的,在这里记录下我的一些学习笔记,一是为了 ...

  8. NPOI 2.1.1 系列(2) 使用NPOI读取List或者datatable数据生成 Excel文档 ;Npoi生成 xlsx 2007以上文档

    结合上一篇文章  NPOI 2.1.1 系列(1) 使用NPOI读取 Excel文档 ;NpoiExcelHelper 导入导出 2003格式 2007格式的 Excel; Npoi 导出 xlsx ...

  9. FastJson---高性能JSON开发包

    SVN:http://code.alibabatech.com/svn/fastjson/trunk/WIKI:http://code.alibabatech.com/wiki/display/Fas ...

  10. Python入门学习:网络刷博器爬虫

    1.比较有趣,可以不断刷新指定的网址 2.源码: #!/usr/bin/env python3 # -*- coding: utf-8 -*- import webbrowser as web imp ...