Actually, Thomas' code example can alternatively be written in a more concise fashion, using appropriate overloaded query methods:
Code:
JdbcTemplate jt = new JdbcTemplate(dataSource);
List results = jt.query(
"select 'Spring' as name, sysdate, systimestamp from dual",
new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Map rowData = new LinkedHashMap(3);
rowData.put("name", rs.getString(1));
rowData.put("sysdate", rs.getTimestamp(2));
rowData.put("systimestamp", rs.getTimestamp(3));
return rowData;
}
});
Two conveniences are leveraged in the above: Firstly, passing in a SQL string rather than coding a PreparedStatementCreator; secondly, using a RowMapper callback rather than a RowCallbackHandler/ResultReader. The latter allow to build any kind of result, while the former assumes one object per row, to be returned as List. So if you want to build a List with one object per row, I recommend to use a RowMapper as callback.
Juergen