Spring jdbctemplate queryforlist (String sql, class<t> ElementType) Easy to use-reproduced

Source: Internet
Author: User

Original address:

http://blog.csdn.net/will_awoke/article/details/12617383

has been using ORM, today with JdbcTemplate again depressed once again.

First look at this method:

At first glance, I want to pass a generic T (the actual code execution, this T can be my custom bean), and then I can return a list<t>, that is, the collection of generics (pure ORM idea Ah!). But also dug a big pit ~)

Thus, the following code appears:

[Java]View Plaincopy
    1. list<student> list = jdbctemplate.queryforlist (sql, Student.   Class);


One execution, found out the exception:

ERROR [Com.ruhuiyun.studentmanager.aop.LogAdvice]- Org.springframework.jdbc.IncorrectResultSetColumnCountException:Incorrect column count:expected 1, actual 8:incorre CT column count:expected 1, actual 8

The exception is very clear, need one, to the people eight, that is, they are not saved list. Very strange, after a search, found not so, and ran off ~

Originally this t, only supports integer.class string.class this kind of single data type, its own defined bean does not support. So I'm over the idea of this ORM.


Feelings if there is a need to encapsulate an object, you have to do it yourself.

This jdbctemplate is really unable to spit groove ~ as if back to the ancient times ~!

Update: wrote a wheel for Spring jdbctemplate query result set map reverse generation Java entity, http://blog.csdn.net/will_awoke/article/details/ 27683703, interested can look under.

Reference article:

http://forum.spring.io/forum/spring-projects/data/122343- Comparison-between-queryforlist-and-query-working-with-a-list-of-objects

Spring jdbctemplate queryforlist (String sql, class<t> ElementType) Easy to use-reproduced

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.