Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the queryForList of jdbcTemplate in java?

Shulou Source: shulou.com Published: 2022-06-03 14:51:13 11月14日 Update

In this issue, the editor will bring you what the queryForList of jdbcTemplate in java is like. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

Do you really understand the queryForList in jdbcTemplate?

Is your imaginary queryForList supposed to look like this?

String sql = "select * from person"; List persons = jdbcTemplate.queryForList (sql, Person.class)

And then, you ordered run excitedly.

The program comes out of something you can't even dream of, isn't it list? Why is expected 1?

I have a total of 7 pieces of data, why actual 4?

I'm still young. Why didn't you put me through this?

There is only one truth:

Pass the corresponding class, create the singleColumnRowMapper, that is, take only one column of values, and then take a look at the documentation comments

You can see that you have used too many ORM frameworks. This thing does not support custom bean, and this class only supports basic types such as Integer,String.

Now do you understand what except 1 actually 4 means?

People expect to return one column, but you have returned four columns, do not understand? Let me give you an example.

String sql = "select id from person"; List ids = jdbcTemplate.queryForList (sql, Integer.class)

If you return the id column, you can use queryForList. The list is a collection of all the id.

This is what the queryForList of jdbcTemplate in java is like. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Tags: Content that is analysis support excitement professionalism things small and medium-sized that is examples rich in content only unexpected meaning data documents articles more framework Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info macOS Shulou Information vpn