Find the solution: http://www.cnblogs.com/wumian/articles/2012-10-25-2056.html
Call the spring JDBC interface:
User User = (User) this. The jdbcTemplate. QueryForObject (" SELECT * FROM the User WHERE ID = 1 "to the User. The class).
Error is reported as follows:
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) |
Probably means:
the data found has 4 columns, it converts the first column in jdbc.queryForObject ("SELECT * FROM USER WHERE ID = 1", User.class); to User.class, so expected 1, actual 6, Expected 1 column, but the data found there are 4 columns
Modification:
RowMapper <User> rm = ParameterizedBeanPropertyRowMapper.newInstance (User.class); User user = (User) this.jdbcTemplate.queryForObject ("SELECT * FROM USER WHERE ID = 1", rm);
Error when calling jdbcTemplate.queryForList spring-org.springframework.jdbc.IncorrectResultSetColumnCountException