Can I use queryForMap
if there are multiple rows returned by the query.
For a single row, the below code works fine.
public Map<String, Object> retrieveMultipleRowsColumns(String deptName){
return jdbcTemplate.queryForMap("SELECT DEPT_ID,DEPT_NAME FROM DEPT WHERE DEPT_NAME = ?", deptName);
}
How to modify this for multiple rows?
Use queryForList
see the javadoc for full details. It returns List<Map<String,Object>>
public List<Map<String, Object>> retrieveMultipleRowsColumns(String deptName){
return jdbcTemplate.queryForList("SELECT DEPT_ID,DEPT_NAME FROM DEPT WHERE DEPT_NAME = ?", deptName);
}