angus
angus

Reputation: 3320

JdbcTemplate multiple columns

I have an SQL that will return the following result: enter image description here

So basically the relationship will be NAME -> MIDDLE -> FAMILY meaning one NAME can have multiple MIDDLE and one MIDDLE can have multiple FAMILY.

I prefer not to create a DAO that will support this table output, ideally I would like to get a Collection of List & Map something like this: List<String<Map<Map>

How can I fetch the data via JdbcTemplate ?

Thank you

Upvotes: 2

Views: 10771

Answers (1)

mohammedkhan
mohammedkhan

Reputation: 975

queryForList might be what you are looking for:

List<Map<String, Object>> rows = jdbcTemplate.queryForList("SELECT name, middle, family FROM table");

Every Map in this List represents a row in the returned query, the key represents the column name, and the value is the value of that column for that row.

WRT having unique entries for duplicated rows, you could manipulate the data returned from this to suit what you need. Or, you could use query that takes a RowMapper which will define how each row of your query should be processed.

It's a little hard to understand how you want the data returned because List<String<Map<Map> doesn't make sense to me.

Upvotes: 7

Related Questions