将ResultSet的结果存放到vector 中,然后返回这个vector。在main中获取这个vector,但是vector中的每一个元素都变成了ResultSet中的最后一条纪录。但在存放过程中检查却是正确的。为什么??

解决方案 »

  1.   

    把你存入vector的那段代码帖出来 
    在线等
      

  2.   

    public class manage
    {
    private material temp=new material();
    private ResultSet rs=null;
    public Vector getResult(String semester)
    { Vector<material> list=new Vector<material>();
    try
    {
    DBConnect db=new DBConnect();
         String sql="Select * from mplans where  学期='"+semester+"'";     
         rs=db.executeQuery(sql);
         while(rs.next())
         {
         temp.setClassnum(new String(rs.getString(1).getBytes("ISO8859-1"),"GBK"));
         temp.setClassname(new String(rs.getString(2).getBytes("ISO8859-1"),"GBK"));
         temp.setBook(new String(rs.getString(3).getBytes("ISO8859-1"),"GBK"));
         temp.setAuthor(new String(rs.getString(4).getBytes("ISO8859-1"),"GBK"));
         temp.setPublisher(new String(rs.getString(5).getBytes("ISO8859-1"),"GBK"));
         temp.setYear(new String(rs.getString(6).getBytes("ISO8859-1"),"GBK"));
         temp.setCharge(new String(rs.getString(7).getBytes("ISO8859-1"),"GBK"));
         temp.setAmount(new String(rs.getString(8).getBytes("ISO8859-1"),"GBK"));
         temp.setTeachers(new String(rs.getString(9).getBytes("ISO8859-1"),"GBK"));
         temp.setSemester(new String(rs.getString(10).getBytes("ISO8859-1"),"GBK"));
         list.add(temp);
         }
         rs.close();
         db.close();
    }
    catch(Exception e)
    {
    System.out.println(e);
    } return list;
    }

    public static void main(String arg[])
    {
    manage f=new manage();
    Vector<material> a=new Vector<material>();
    a=f.getResult("2005-2005下");
    for(int i=0;i<a.size();i++)
          { 
              material t=(material)a.get(i);
          }
        }
    }
      

  3.   

    在main中的vector a中所有元素的值都一样了,都是数据库最后一条纪录
      

  4.   

    private material temp ;
    while(rs.next())
    {
    temp = new material();
    ...
    ...
    ...
    ...list.add(temp);
    }