public List<Admin> getAllAdmin() {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
List<Admin> adminList = new ArrayList<Admin>();
int count = 0;
try {
conn = JdbcUtil.getConnection();
String sql = "select id,adminid,adminname,password,time from admin";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
Admin[] adminArr = new Admin[]{};
while (rs.next()) {
//todo
}
}catch (SQLException e) {
e.printStackTrace();
}
return adminList;
}

解决方案 »

  1.   

    每个属性拿出来,set一次,list.add()一次,OK,
      

  2.   

    我的想法就是while的时候把调用admin对象的set方法把这个admin对象封装起来 然后就根据那个count的大小用了一个for循环
    但是提示说是下标越界 
      

  3.   

    如果你的pojo类(就是Admin)写的比较正常的话
    把Admin[] adminArr = new Admin[]{};换成Admin admin=new Admin();
    //todo里面代码为
    admin.setAdminId(rs.getInt(2));//具体的set方法要看你自己怎么写的
    admin.setAdminname(rs.getString(3));
    admin.setPassword(rs.getString(4));//这里如果你的数据库中的password是varchar类型的话
    //time属性,要看你用的哪一个类了,可以通过得到毫秒数来创建对应的Admin对象的time
    adminList.add(admin);
    我也在学习,不知道能不能帮到你
      

  4.   


    public List<Admin> getAllAdmin() {
            Connection conn = null;
            PreparedStatement ps = null;
            ResultSet rs = null;
            List<Admin> adminList = new ArrayList<Admin>();
            int count = 0;
            try {
                conn = JdbcUtil.getConnection();
                String sql = "select id,adminid,adminname,password,time from admin";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                
                while (rs.next()) {
                  Admin admin = new Admin();
          admin.setId(rs.getString(1)) ;  
                  admin.setAdminid(rs.getString(2)) ;  
                  admin.setAdminname(rs.getString(3)) ;
                  admin.setPassword(rs.getString(4)) ;  
                  admin.setTime(rs.getString(5)) ;   
                  adminList.add(admin);
                }
            }catch (SQLException e) {
                e.printStackTrace();    
            }
            return adminList;
        }
      

  5.   

    你把你的实现代码(while循环体)都贴出来,让大家伙看看,哪里有问题