62,614
社区成员
发帖
与我相关
我的任务
分享
public class StudentDaoImpl implements StudentDao {
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public List<Student> findStudents() {
String sql = "select * from t_student";
final List<Student> stus = new ArrayList<Student>();
jdbcTemplate.query(sql, new RowCallbackHandler(){
int num= 0;
public void processRow(ResultSet rs) throws SQLException {
Student stu = new Student();
stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name"));
stu.setAge(rs.getInt("age"));
stus.add(stu);
}
});
return stus;
}