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, ...
随机推荐
- php 二维数组打乱顺序
public function shuffle_assoc($list) { if (!is_array($list)) return $list; $keys = array_keys($list) ...
- 关于源码输出,浏览器不解析Html标签
有时候根据需要我们需要看到浏览器上源码效果如: 但是我如果在html中输入 <a href = 'http://www.baidu.com'>百度</a>那么问题来了,总是显示 ...
- 《Qt数据类型》--QByteArray,QString,int,hex之间的转化
对于QString和QByteArray,他们都有一个toInt的静态函数,QString::toInt()是根据string的字面值转化为int类型,比如string:"123" ...
- PinnedListView分析二
在PinnedListView分析一中还有一些细节在本文做一个补充,主要是view的绘制: 一个view在真正被绘制都是通过canvas来做,在ViewGroup内的z子view,一般再次此之前,还需 ...
- Sublime Text 3 For Mac
安装 Sublime Text 3 下载地址:http://www.sublimetext.com/3 我此时使用的是Build 3083版本. 安装 Package Control 这个是精华所在, ...
- 关于Unity中坐标系的种类
坐标空间 1:物体空间: 3D物体自己的坐标空间 一般设计时几何体以中心为原点,人物以双脚为原点; 2: 世界空间: 3D物体在场景中的世界坐标, 整个游戏场景的空间; 3: 摄像机空间: 以观察摄像 ...
- Self20171218_Eclipse+TestNg HelloWorld
作为一个经典的入门例子,这里展示如何开始使用TestNG单元测试框架. 使用的工具 : TestNG 6.8.7 Maven 3 Eclipse IDE TestNG下载并安装 从这里 http:// ...
- 解决maven jmxtools 缺失的问题
原因:有版权,所以maven仓库基本都下架了jmxtool. 目前可用的,我就找到了wso2这家,配置如下: <project xmlns="http://maven.apache.o ...
- 第三百二十五节,web爬虫,scrapy模块标签选择器下载图片,以及正则匹配标签
第三百二十五节,web爬虫,scrapy模块标签选择器下载图片,以及正则匹配标签 标签选择器对象 HtmlXPathSelector()创建标签选择器对象,参数接收response回调的html对象需 ...
- (转)Live555中RTSPClient分析
有RTSPServer,当然就要有RTSPClient. 如果按照Server端的架构,想一下Client端各部分的组成可能是这样:因为要连接RTSP server,所以RTSPClient要有TCP ...