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语言判断向量中是否存在一个元素
判断ori_data[,1]中是否存在元素a: a %in% ori_data[,1] 如果存在返回 true,否则返回 false
- 在kali linux之下 下载并解压的文件名呈现乱码 解决方案
从Linux往 windows拷贝文件或者从windows往Linux拷贝文件,有时会出现中文文件名乱码的情况,出现这种问题的原因是因为,windows的文件名中文编码默认为GBK,而Linux中默认 ...
- Python之cv2
1.读取图片 import cv2 img = cv2.imread('./test.jpg') 读取出来的图片是numpy.ndarray格式,值是0-255, img的形状是 (图片高度,图片宽度 ...
- python2 python3 字符串 编码格式 处理
使用python的ctypes调用c语言中的函数,传入字符串,打印输出异常.解决方法记录于此. 参考连接: http://blog.csdn.net/u011546806/article/detail ...
- SpringMVC系列(十四)Spring MVC的运行流程
Spring MVC的运行流程图: 1.首先看能不能发送请求到Spring MVC的DispatcherServlet的url-pattern2.如果能发送请求,就看在Spring MVC中是否存在对 ...
- unity执行顺序问题(如何再次执行start方法)
2016-09-08 20:13 2084人阅读 评论(1) 收藏 举报 分类: unity3D(66) 版权声明:本文为博主原创文章,未经博主允许不得转载. unity执行顺序的文章已经很多了, ...
- nodejs基础 -- express框架
Node.js Express 框架 Express 简介 Express 是一个简洁而灵活的 node.js Web应用框架, 提供了一系列强大特性帮助你创建各种 Web 应用,和丰富的 HTTP ...
- 使用VS2017新建的Web项目报错:Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1
使用VS2017新建的Web项目报错: 看到这样的错误提示,毫无意义.赶脚这应该是VS2017的BUG,没有显示错误的位置.于是用dotnet restore手动还原,结果在控制台中终于显示了详细的错 ...
- Python内部机制。
type ,object ,__class__ ,__bases__ ,__metaclass__ , -------------------------不明白的地方----------------- ...
- winform程序开机自动启动
app.manifest <requestedExecutionLevel level="requireAdministrator" uiAccess="false ...