怎么创建的ArrayList??
说出来看看

解决方案 »

  1.   

    怎么创建的ArrayList??
    说出来看看
      

  2.   

    public java.util.AbstractList queryByBranch(String branch_id)
      {
        ArrayList al=new ArrayList();
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try
     {
       con = DBManager.getConnection();
       stmt = con.createStatement();
       String temp = " where branch_id='" + branch_id + "'";
       sb.append(temp);
       rs = stmt.executeQuery(sb.toString());
       ResultSetMetaData rsmd = rs.getMetaData();
       int cols = rsmd.getColumnCount();
       if(rs.next()!=false)
       {
         ArrayList al0=new ArrayList();
         for (int i = 1; i <= cols; ++i)
         {
           if(rs.getString(i)==null)
           {
             al0.add("null");
           }
           else
           {
               al0.add(rs.getString(i));
           }
         }
         al.add(al0);
       }
     }
     catch(Exception e)
       {
       e.printStackTrace();
    }
     finally
     {
         try
         {
           if(rs!=null)
           {
             rs.close();
           }
         }
         catch(Exception e){}
         try
         {
           if(stmt!=null)
           {
             stmt.close();
           }
         }
         catch(Exception e){}
         try
       {
         if(con!=null)
         {
           con.close();
         }
       }
       catch(Exception e){}
     }
     return al;
    }
      

  3.   

    你这个方法应该只能得到一条记录吧?你用的if (rs.next())……用while(rs.next())
      

  4.   

    你的a1中当然只有一个item了,你的代码中
    if(rs.next()!=false)
       {
         ArrayList al0=new ArrayList();
         for (int i = 1; i <= cols; ++i)
         {
           if(rs.getString(i)==null)
           {
             al0.add("null");
           }
           else
           {
               al0.add(rs.getString(i));
           }
         }
         al.add(al0);
       }注意你的第一行代码用的是if,而不是while。
      

  5.   

    楼上各位兄弟讲得很对,记录集需要用循环来取出所有数据的!
    必须用while!
      

  6.   

    public java.util.AbstractList queryByBranch(String branch_id)
      {
        ArrayList al=new ArrayList();
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        try
     {
       con = DBManager.getConnection();
       stmt = con.createStatement();
       String temp = " where branch_id='" + branch_id + "'";
       sb.append(temp);
       rs = stmt.executeQuery(sb.toString());
       ResultSetMetaData rsmd = rs.getMetaData();
       int cols = rsmd.getColumnCount();
       while(rs.next())
       {
     
         for (int i = 1; i <= cols; ++i)
         {
           if(rs.getString(i)==null)
           {
             al.add("null");
           }
           else
           {
               al.add(rs.getString(i));
           }
         }
         
       }
     }
     catch(Exception e)
       {
       e.printStackTrace();
    }
     finally
     {
         try
         {
           if(rs!=null)
           {
             rs.close();
           }
         }
         catch(Exception e){}
         try
         {
           if(stmt!=null)
           {
             stmt.close();
           }
         }
         catch(Exception e){}
         try
       {
         if(con!=null)
         {
           con.close();
         }
       }
       catch(Exception e){}
     }
     return al;
    }这样写比较好