当前位置: 代码迷 >> J2EE >> 把结果集封装成list 遇到有关问题了 高手看看怎么处理
  详细解决方案

把结果集封装成list 遇到有关问题了 高手看看怎么处理

热度:286   发布时间:2016-04-22 02:57:20.0
把结果集封装成list 遇到问题了 高手看看怎么办
Java code
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;    }


------解决方案--------------------
Java code
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;    }
  相关解决方案