直接使用mysql包中的类 执行sql语句

好像使用这个方法并没有简单,而更复杂了。。。惊讶

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

猜你喜欢

转载自blog.csdn.net/csdn13461916098/article/details/80417882