【发布时间】:2014-06-30 10:46:51
【问题描述】:
我正在尝试一个关于如何使用ResultSetExtractor 的演示,但我无法让它工作。
下面是我试过的代码:
public String retrieveDeptName(final int deptId){
String deptName = (String)jdbcTemplate.update(new PreparedStatementCreator() {
@Override
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
return con.prepareStatement(SELECT_DEPT);
}
}, new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps) throws SQLException {
ps.setInt(1, deptId);
}
},new ResultSetExtractor() {
@Override
public Object extractData(ResultSet rs) throws SQLException,
DataAccessException {
if (rs.next()) {
return rs.getLong(2);
}
return null;
}
});
System.out.println(deptName);
}
错误是:
The method update(String, Object[], int[]) in the type JdbcTemplate is not applicable for the arguments (new PreparedStatementCreator(){}, new PreparedStatementSetter(){}, new ResultSetExtractor(){})
虽然很清楚,但我很惊讶link 是如何工作的?
请指教。
【问题讨论】:
标签: java spring spring-3 jdbctemplate