好像使用这个方法并没有简单,而更复杂了。。。
public List<Student> getAllStus()
{
List<Student> stuList=new ArrayList<Student>();
Connection conn=DButil.getDbConn();
String sql="select * from stu_info";
QueryRunner qr=new QueryRunner();
tyr{
qr.execute(conn,sql,new ResultSetHandler(){
public List<Student> handle(final ResultSet rs){
final List<Student> stuList=new ArrayList<Student>();
try{
while(rs.next()){
stuList.add(new Student(类Student 的所有属性));
}
}catch(final SQLException e){
e.printStackTrace();
}
return stuList;
}//handle方法结束
}//匿名内部类结束,nulll);
}//外层try 结束
}//getAllStus
本文探讨了一种从数据库中获取学生信息的方法,通过使用QueryRunner执行SQL查询,并采用匿名内部类处理结果集来填充学生对象列表。然而,这种方法似乎并未简化原有流程反而增加了复杂度。
742

被折叠的 条评论
为什么被折叠?



