日期:2014-05-18  浏览次数:20705 次

Hashtable 的声明位置没搞懂
1>
        Connection   conn=getConnection();
        Vector   list=new   Vector();
        Hashtable   ht=new   Hashtable();
        try
        {
              stmt=conn.createStatement();
              ResultSet   rs=stmt.executeQuery( "select   sortID,sortName ");
              while(rs.next()   )
              {
                    int   field   =rs.getInt(1);
                    String   value=rs.getString(2);
                    ht.put(field,value);
                    list.add(ht);
              }
                           
        }catch(SQLException   e)
        {}

2>

      Connection   conn=getConnection();
        Vector   list=new   Vector();
        try
        {
              stmt=conn.createStatement();
              ResultSet   rs=stmt.executeQuery( "select   sortID,sortName ");
              while(rs.next()   )
              {
                    Hashtable   ht=new   Hashtable();
                    int   field   =rs.getInt(1);
                    String   value=rs.getString(2);
                    ht.put(field,value);
                    list.add(ht);
              }
                           
        }catch(SQLException   e)
        {}


数据表:
        sortID                           sortName
            1                                 计算机
            2                                 园林设计


第一段代码的结果为:
            2                                 园林设计
            1       &nbs