2. Code Example

Inject the DataSource into a bean and in the setter for the DataSource create a SimpleJdbcTemplate. Then the template has many methods for doing updates, queries, and deletes. The example below shows getting a List of Maps from the template.

                
protected SimpleJdbcTemplate simpleJdbcTemplate = null;

@Autowired
public void setDataSource(final DataSource dataSource) {
    this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);
}


List<Map<String, Object>> lPersonMaps = simpleJdbcTemplate.queryForList("SELECT * FROM PERSON");

Map<String, Object> hPerson = lPersonMaps.get(0);

Integer id = (Integer)hPerson.get("ID");
String firstName = (String)hPerson.get("FIRST_NAME");
String lastName = (String)hPerson.get("LAST_NAME");