Connection conn=getConnection();
Vector list=new Vector();
try
{
stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select sortID,sortName,child_sort_id,child_sort_name");
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 child_sort_id child_sort_name
但经过以上程序后,取得的值为:
sortID child_sort_name child_sort_id sortName
sortName 和 child_sort_name 的位置交换了,这是怎么回来呢??如果只有两列的话就正常了
Vector list=new Vector();
try
{
stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select sortID,sortName,child_sort_id,child_sort_name");
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 child_sort_id child_sort_name
但经过以上程序后,取得的值为:
sortID child_sort_name child_sort_id sortName
sortName 和 child_sort_name 的位置交换了,这是怎么回来呢??如果只有两列的话就正常了
改成 Map ht = new LinkedHashMap();就可以了另外,建议你以后不要使用HashTable了