Incorrect column count: expected 1, actual 5,JdbcTemplate queryForList 出错
spring JdbcTemplate queryForList 出错
Incorrect column count: expected 1, actual 5
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
©Copyright 蕃薯耀 2017年7月10日
http://www.cnblogs.com/fanshuyao/
一、问题描述:
查询时使用JdbcTemplate 中的queryForList发生错误,如下:
查询方法如下:
- jdbcTemplate.queryForList(selectSql.toString(), entityClass)
查询sql如下:
- select * from test where 1=1 order by create_time desc limit 0,10
错误如下:
- Incorrect column count: expected 1, actual 5
二、解决方案:
1、上面错误的原因是,查询返回的结果列期望为1,但实际返回的是5列,因为test表中有5个字段,故返回5列。而这个方法参数的解释是这样的:
- Parameters:
- sql SQL query to execute
- elementType the required type of element in the result list (for example, Integer.class)
就是第2个参数在网上说只能是简单类型String或Integer。
2、使用query查询
- jdbcTemplate.query(selectSql.toString(), rowMapper)
但多了一个参数rowMapper,这个参数需要定义为:
- @SuppressWarnings("unused")
- private BeanPropertyRowMapper<T> rowMapper = new BeanPropertyRowMapper<T>(entityClass){
- @Override
- protected void initBeanWrapper(BeanWrapper bw) {
- super.initBeanWrapper(bw);
- }
- };
具体的作用就是进入查询结果转换成实体。
到这步也就解决问题了。
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
©Copyright 蕃薯耀 2017年7月10日
http://www.cnblogs.com/fanshuyao/
Incorrect column count: expected 1, actual 5,JdbcTemplate queryForList 出错的更多相关文章
- 使用JdbcTemplate报 Incorrect column count: expected 1, actual 5错误解决
Incorrect column count: expected 1, actual 5 在使用jdbc的querForObject queryForList的时候,出现Incorrect colum ...
- Incorrect column count: expected 1, actual 5
在使用jdbc的querForObject queryForList的时候,出现Incorrect column count: expected 1, actual 5 比如 String sql = ...
- Incorrect column count: expected 1, actual 2
List<Long> idList = queryForList("ass.pageQuery_sgIds", paramMap, Long.class); 报错:In ...
- Incorrect column count: expected 1, actual 6
JdbcTemplate使用时出现了一些问题: 解决办法:
- QueryError:Incorrect result size: expected 1, actual 0
1.错误描述 QueryError:Incorrect result size: expected 1, actual 0 2.错误原因 3.解决办法
- ORA-00001:unique constraint violated 以及 Incorrect result size: expected 1, actual 0
往数据库中插入数据时报错: www.2cto.com ORA-00001: unique constraint (IDX_CARTON_HEADER)violated. 即往CARTON_ ...
- (后端)org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1,actual 0
两种方案: 用queryForList方法替换queryForObject或者queryForMap,因为这两个方法必须要有值,不能为空. 把这个异常捕获,用try/catch. 这个查询的结果是nu ...
- 调用 jdbcTemplate.queryForList 时出现错误 spring-org.springframework.jdbc.IncorrectResultSetColumnCountException
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- 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, ...
随机推荐
- R语言字符串替换
R gsub Function gsub() function replaces all matches of a string, if the parameter is a string vecto ...
- javascript小技巧[转]
总的来说,如果你要找js 的东西,而不看这两篇的话,肯定要多花好多时间!!哈哈!! 如果你找的javascript的东西的话,建议你 ctrl+F 直接在这个页上找,因为这里80%有你要找的,但是要 ...
- 【转】IT族室内锻炼身体的小妙招
上班族.久坐族近年的健康状况令人堪忧,由于缺乏运动加上长期面对辐射,使上班族身体状况越来越差.专家建议上班族应多加运动,只需小小的动作就能轻松获得健康! 梳头:用木梳从前额至头顶部向后部梳刷,逐渐加快 ...
- http://www.gasi.ch/blog/inside-deep-zoom-1/
In March 2007 Blaise Aguera y Arcas presented Seadragon & Photosynth at TED that created quite s ...
- 使用VMware将Linux装在物理硬盘上,开机即可进入Linux (转)
目录(?)[-] 本文目的 具体操作 1 软件准备 2 安装 21 对硬盘操作 22 创建虚拟机并安装 23 使用Grub引导Linux 1. 本文目的 适合于没有光驱的计算机来安装Linux,还有 ...
- Python判断操作系统类型
代码: import platform def TestPlatform(): print ("----------Operation System--------------------- ...
- IT 运营架构杂谈【前言】
[ 什么是IT 服务 ?] OGC官方的ITIL 服务定义: 中文定义:实施和管理 IT 服务,满足业务的需要.IT 服务管理由IT 服务提供方通过人员.流程和信息技术的适当组合而进行. [ ...
- (笔记)Linux 如何查看线程数最佳解决方案
背景:很多学linux的人都会使用ps查看进程状态,却一直不清楚如何查看线程的状态. 方法:可使用ps -a 或 ps -T命令查看 一.使用ps -a命令查看 比如拿我的测试进程./lc300-le ...
- InnoDB和MyISAM的区别与选择
MyISAM 性能(适合小项目,读快速)MyISAM 是MySQL中默认的存储引擎,比如适合新闻系统,读为主.InnoDB 事务或外键支持(适合大项目,高并发读写)活跃用户20多万时候,也能很轻松应付 ...
- 转换基于Maven的Java项目支持Eclipse IDE
在过去的教程中,使用 Maven 创建了一个Java项目,但是这个项目不能导入到Eclipse IDE中,因为它不是 Eclipse 风格的项目. 这里有一个指南,向您演示如何转换 Maven 生成 ...