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, ...
随机推荐
- springcloud服务已经关但是Eureka还是显示up
该状态持续很久,访问该服务也返回错误,但在注册中心界面,该服务却一直存在,且为UP状态,并且在大约十分钟后,出现一行红色大字:EMERGENCY! EUREKA MAY BE INCORRECTLY ...
- Keil C 中全局变量 extern 的使用
在KEIL C中,有多个源文件使用到全局变量时,可以在一个源文件中定义全局变量,在另外的源文件中用extern 声明该变量,说明该变量定义在别的文件中,将其作用域扩展到此文件. 例如:有以下两个源文件 ...
- python 核心编程 01
特殊变量 python用下划线作为变量的前缀和后缀指定特殊变量._XXX : 不用 'from module import *' 导入, 可以认为是模块中的私有变量__XXX__ : 系统定义的名字_ ...
- JSP字符集编码集合
在这里,我们先说说JSP/Servlet中的几个编码的作用. 在JSP/Servlet 中主要有以下几个地方可以设置编码,pageEncoding="UTF-8".contentT ...
- Lucene系列三:Lucene分词器详解、实现自己的一个分词器
一.Lucene分词器详解 1. Lucene-分词器API (1)org.apache.lucene.analysi.Analyzer 分析器,分词器组件的核心API,它的职责:构建真正对文本进行分 ...
- e781. 设置JList中的选择模式
// The default mode is MULTIPLE_INTERVAL_SELECTION String[] items = {"A", "B", & ...
- Python操作SQLServer示例(转)
转自:http://www.cnblogs.com/lrzy/p/4346781.html 本文主要是Python操作SQLServer示例,包括执行查询及更新操作(写入中文). 需要注意的是:读取数 ...
- Eclipse使用资源管理器打开选中文件/目录
- Python property,属性
參考资料 http://www.ibm.com/developerworks/library/os-pythondescriptors/ 顾名思义,property用于生成一个属性.通过操作这个属性. ...
- SqlException with message "Caught java.io.CharConversionException." and ERRORCODE=-4220
Technote (troubleshooting) Problem(Abstract) When an application uses the IBM Data Server Driver for ...