关系管理系统:CustomerDaoimpl中添加用户代码getAll()

public List<Customer> getAll(){
        
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        try{
            conn = JdbcUtils.getConnection();
            String sql = "select * from customer";
            st = conn.prepareStatement(sql);
            rs = st.executeQuery();
            
            List list = new ArrayList();
            
            while(rs.next()){
                Customer c = new Customer();
                c.setBirthday(rs.getDate("birthday"));
                c.setCellphone(rs.getString("cellphone"));
                c.setDescription(rs.getString("description"));
                c.setEmail(rs.getString("email"));
                c.setGender(rs.getString("gender"));
                c.setId(rs.getString("id"));
                c.setName(rs.getString("name"));
                c.setPreference(rs.getString("preference"));
                c.setType(rs.getString("type"));
                
                list.add(c); //查询所用用户用 用list保存
            }
            
            return list.size()>0 ? list : null;//判断list是否为空,不为空即显示数据
            
        }catch (Exception e) {
            throw new DaoException();
    
        }finally{
            JdbcUtils.release(conn, st, rs);
        }
原文地址:https://www.cnblogs.com/lichone2010/p/3175521.html