Querying for Multiple Rows
Now, query or extract multiple rows from database, and convert it into a List.
Map it manually
In mutiple return rows, RowMapper is not supported in queryForList() method, you need to map it manually.
public List<Customer> findAll(){ String sql = "SELECT * FROM CUSTOMER"; List<Customer> customers = new ArrayList<Customer>(); List<Map> rows = getJdbcTemplate().queryForList(sql); for (Map row : rows) { Customer customer = new Customer(); customer.setCustId((Long)(row.get("CUST_ID"))); customer.setName((String)row.get("NAME")); customer.setAge((Integer)row.get("AGE")); customers.add(customer); } return customers; }
For more examples;
Source: http://www.mkyong.com/spring/spring-jdbctemplate-querying-examples/
Advertisements