for循环遍历resultset
每次get一个出来,然后使用list的add方法一个一个往里添加,不知道楼主的要求是不是就是这样,如果楼主希望一条记录作为一个list的一个元素,建议不要用list
用hashtable或者vector,这两个容器类可以放置对象集元素,list好像只能放置string类型的对象数据

解决方案 »

  1.   

    private Collection customerList()
    throws SQLException
    {
    Connection conn=null;

    try
    {
    javax.sql.DataSource dataSource=
    servlet.findDataSource(Action.DATA_SOURCE_KEY);
    conn=dataSource.getConnection();

    CallableStatement cstmt=conn.prepareCall("{call customer_select_for_list}");

    ResultSet rs=cstmt.executeQuery();
    ArrayList list=new ArrayList();  //把表格行保存到数组
    while(rs.next())
    {
    ywBean sForm=new ywBean(); //生成表格行

    //写入数据
    sForm.setId(String.valueOf(rs.getInt(1)));
    sForm.setName(rs.getString(2));
    list.add(sForm);
    }
    rs.close();
    cstmt.close();
    return list;
    }
    catch(Exception e)
    {
    System.out.println(e.getMessage ());
    return null;
    }
    finally
    {
    if(conn!=null)
    {
    conn.close();
    }
    }
    }
      

  2.   

    Collection listuser{
      ArrayList Result=new ArrayList();
       ;
       ;
      while (rs.next()){
       String s=rs.getString(1);
       Result.add(s);
      }
      return Result;
    }