NamedParameterJdbcTemplate jt = new NamedParameterJdbcTemplate(mockDataSource);
Map params = new HashMap();
params.put("id", new SqlParameterValue(Types.DECIMAL, new Integer(1)));
params.put("country", "UK");
Customer cust = (Customer) jt.query(SELECT_NAMED_PARAMETERS, params, new ResultSetExtractor() {
public Object extractData(ResultSet rs) throws SQLException, DataAccessException {
rs.next();
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
});
assertTrue("Customer id was assigned correctly", cust.getId() == 1);
assertTrue("Customer forename was assigned correctly", cust.getForename().equals("rod"));
}