小妹向想问下大家。。从第一个SQL里面可以得到字段UserID,我在第二个SQL里面需要用到这个UserId作为查询条件,但当第一个SQL里查询出来的数据为多条时,我用1个FOR循环将其
//   resultList为第一个SQL的ARRAYLIST
for (int i = 0; i < resultList.size(); i++) {
     HashMap dataMap = (HashMap) resultList.get(i);
//dao.researchuser为第二个查询的方法
    resultList2 = dao.researchuser(dataMap);
}但我现在需要取得resultList2 .size。在页面显示查询出来的条数,但始终取得是最后1个循环的条数,例如:第一个SQL查询出来2条数据,ID为1和2,然后循环查询SQL2,当ID是1的时候查询出3条数据,页面显示3,ID为2的时候,查询出10条,页面显示10

解决方案 »

  1.   

    要看你dao.researchuser(dataMap)里面是怎么写的,贴出来看看
      

  2.   

    用 in 不就可以了            select * from table1 where userid in (select usrid from table2)
      

  3.   

    直接告诉你dao.researchuser(dataMap)里面的参数
    private String researchAllSql(Object data) {
        HashMap dataMap = (HashMap) data;        
       String userid = dataMap.get("SERVICE_CODE");后面就是SQLWHERE USERID=userid ;}
      

  4.   

    resultList2 = dao.researchuser(dataMap);
    每循环一次resultList2就被重新指定了,所以resultList2 .size取得的都是循环到最后一次的size。应该把每次循环的至add到resultList2中,这样才是所有的记录
      

  5.   

    ArrayList的一个方法,将指定的元素追加到此列表的尾部,因为你是循环通过userid来查找的,每次查的的结果应该都追加到列表中,不然的话,它就只能得到最后一次循环查出来的结果了啊
      

  6.   

    需要重新定义个ARRAYLIST、然后ADD?在循环里ADD?
      

  7.   

    拼成一个sql搜索
    或者把每次搜索的加到一个数组或者列表里面。
      

  8.   

    resultList2.add( dao.researchuser(dataMap));?????????
      

  9.   

    resultList2 在循环前 new 一个
    然后
     resultList2.addAll(dao.researchuser(dataMap));
      

  10.   

    resultList2 =new ArrayList();
    //   resultList为第一个SQL的ARRAYLIST
    for (int i = 0; i < resultList.size(); i++) {
         HashMap dataMap = (HashMap) resultList.get(i);
    //dao.researchuser为第二个查询的方法
        resultList2.addAll(dao.researchuser(dataMap));
    }