直接上代码
StringBuffer sql = new StringBuffer("select * from A t where t.id= ?");
PreparedStatementSetter statementSetter = new PreparedStatementSetter() {
@Override
public void setValues(PreparedStatement preparedStatement) throws SQLException
{
preparedStatement.setInt(1,Id);
}
};
this.query(sql.toString(), statementSetter, new ResultSetExtractor<A>() {
public A extractData(ResultSet rs) throws SQLException {
A a= new A();
a.setId(rs.getInt("Id"));
return a;
}
});
这样就可以了
更多推荐
JdbcTemplate的query方法防治sql注入
发布评论