An error occurred while calling Jdbctemplate.queryforlist Spring-org.springframework.jdbc.incorrectresultsetcolumncountexception

Source: Internet
Author: User
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.