Created
November 3, 2011 13:56
-
-
Save aziz781/1336542 to your computer and use it in GitHub Desktop.
Spring JDBC: simple way to excute a query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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