标签:blog http io ar sp java for 数据 div
查找到解决方法: http://www.cnblogs.com/wumian/articles/2012-10-25-2056.html
调用spring jdbc接口:
User user = (User) this .jdbcTemplate.queryForObject( "SELECT * FROM USER WHERE ID = 1" , User. class ); |
报错如下:
Exception in thread "main" org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1 , actual 4 at org.springframework.jdbc.core.SingleColumnRowMapper.mapRow(SingleColumnRowMapper.java: 87 ) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java: 92 ) at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java: 1 ) at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java: 445 ) at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java: 395 ) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java: 455 ) at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java: 463 ) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java: 471 ) at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java: 476 ) at com.ylp.dao.UserDao.getById(UserDao.java: 45 ) at com.ylp.dao.Test.main(Test.java: 17 ) |
大概意思是:查出的数据有4列,它把jdbc.queryForObject("SELECT * FROM USER WHERE ID = 1", User.class);中的第一列转换成User.class,所以 expected 1, actual 6,预期1列,但查出来的数据有4列
修改:
RowMapper<User> rm = ParameterizedBeanPropertyRowMapper.newInstance(User. class ); User user = (User) this .jdbcTemplate.queryForObject( "SELECT * FROM USER WHERE ID = 1" , rm); |
标签:blog http io ar sp java for 数据 div
原文地址:http://www.cnblogs.com/AloneSword/p/4104146.html