2V0-72.22PSE · Question #84
Which two statements are true regarding result set handling? (Choose two.)
The correct answer is C. JdbcTemplate can return each row of a ResultSet as a Map. D. RowMapper interface is used for mapping a single row of a ResultSet to an object. C is correct because JdbcTemplate provides queryForList() and queryForMap() methods that represent each row as a Map<String, Object>, where column names are the keys - useful when you don't want to define a custom mapper. D is correct because RowMapper<T> is a functional…
Question
Which two statements are true regarding result set handling? (Choose two.)
Options
- AJdbcTemplate is configured with a default RowMapper.
- BJdbcTemplate can return each row of a ResultSet as a Set.
- CJdbcTemplate can return each row of a ResultSet as a Map.
- DRowMapper interface is used for mapping a single row of a ResultSet to an object.
- ERowMapper interface cannot be used for multiple row queries.
How the community answered
(24 responses)- A4% (1)
- C88% (21)
- E8% (2)
Explanation
C is correct because JdbcTemplate provides queryForList() and queryForMap() methods that represent each row as a Map<String, Object>, where column names are the keys - useful when you don't want to define a custom mapper.
D is correct because RowMapper<T> is a functional interface with a single method mapRow(ResultSet rs, int rowNum) that converts one row into a domain object. Spring calls this per-row, and it works with both single-row (queryForObject) and multi-row (query) methods, returning a List<T> in the latter case.
Why the distractors are wrong:
- A:
JdbcTemplatehas no defaultRowMapper- you must always supply one explicitly or use a built-in alternative likeBeanPropertyRowMapper. - B: Rows are returned as
Map, neverSet- aSethas no column-to-value semantics. - E: This is the opposite of the truth;
RowMapperis heavily used for multi-row queries viajdbcTemplate.query(sql, rowMapper), which returns aList<T>.
Memory tip: Think "Columns → Collection (Map)" for option C, and "Domain object per row → DRowMapper" for option D. The key trap is E - don't confuse RowMapper (maps one row, used for many) with ResultSetExtractor (processes the entire ResultSet at once).
Topics
Community Discussion
No community discussion yet for this question.