Spring JDBC Framework simplifies the use of JDBC and helps to avoid common errors.
The following example shows querying for list of objects using an implementation of
RowMapper interface.
/**
* Initialize context and get the JdbcTemplate
*/
ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");
DataSource dataSource = (DataSource) appContext.getBean("dataSource");
JdbcTemplate template = new JdbcTemplate(dataSource);
List<BugStat> names = template.query("select * from BUG_STAT", new RowMapper<BugStat>() {
@Override public BugStat mapRow(ResultSet rs, int arg1) throws SQLException { return new BugStat(rs.getInt("ID"),
rs.getString("STATUS"),
rs.getInt("COUNT"));
}