使用 Spring JDBC,我发现自己一直在做这样的事情:
NamedParameterJdbcTemplat njt = ...;
String SQL = "SELECT blah FROM blah_table WHERE column = :condition";
SqlParameterSource params = new MapSqlParameterSource('condition', variableName);
List<Integer> rows = njt.query(SQL, params, Integer.class);
if(rows.size() == 0)
{
//record did not exist, whew avoided index out of bounds exception
}
//do something with rows.get(0);
应该有更好的方法吧?