java,sql查询算法问题
 try {
                        String sql = "SELECT NAME,PASS,AGE,QQ,PHONE FROM BASICD WHERE NAME='XIAOMING'";
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            int qlen = quValue.size();
            while (rs.next()) {
                User user = new User();
                                //NAME,PASS,AGE,QQ,PHONE
                                //怎么把上面已知的5个值,在未知个数的情况下,放到相应的类方法里。

                            ?
            }

        } catch (SQLException e) {

        }

                class user{
                        String NAME;
                        String PASS;
                        int AGE;
                        String  QQ;
                        String PHONE;
                        public  setvalue(String NAME,String PASS,int AGE,String QQ,String PHONE){
                               this.NAME = NAME;
                                     this.PASS = PASS;
                                     this.AGE = AGE;
                                     this.QQ = QQ;
                                    this.PHONE = PHONE;
                        }
                }

5个回答

List<User> users = new ArrayList<User>();
  while (rs.next()) {
                User user = new User();
                 user.setValue(rs.getString("name"),rs.getString("pass"),rs.getInt("age"),rs.getString("qq"),rs.getString("phone"));
                                users.add(user);
            }

你这个用List装不行么,这样操作也方便

封装到集合或po对象中

user.setValue(rs.getString("name"),rs.getString("pass"),rs.getInt("age"),rs.getString("qq"),rs.getString("phone"));
这个不行吗?

封装到PO对象中再放到集合里?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问