Skip to content

Instantly share code, notes, and snippets.

@aziz781
Created November 3, 2011 13:56
Show Gist options
  • Save aziz781/1336542 to your computer and use it in GitHub Desktop.
Save aziz781/1336542 to your computer and use it in GitHub Desktop.
Spring JDBC: simple way to excute a query
// first get 'dataSource'
// @Autowired
// private DataSource dataSource;
private Object[] geStatus() {
try {
JdbcTemplate template = new JdbcTemplate(dataSource);
Object[] result = (Object[]) template.queryForObject(SQL, new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Object[]{rs.getString(1), sdf.format(rs.getDate(2))};
}
});
return result;
} catch (Throwable t) {
return new Object[]{"FAILED TO OBTAIN STATUS", new Date()};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment