这两段结果集的代码运行后为什么有不同的结果?
说明:rs为从数据库查询后返回的结果集,包含2行数据。代码1:
Vector rowData=new Vector();
while(rs.next()){
Vector currentRowData=new Vector();
currentRowData.addElement(rs.getString(1);
currentRowData.addElement(rs.getString(2);
currentRowData.addElement(rs.getString(3);
currentRowData.addElement(rs.getDouble(4);
rowData.addElement(currentRowData);
}
System.out.println(rowData);
代码2:
Vector rowData=new Vector();
while(rs.next){
rowData.addElement(getCurrentRowData(rs));
}
System.out.println(rowData);
public static Vector getCurrentRowData(ResulSet rs){
Vector currentRowData=new Vector();
currentRowData.addElement(rs.getString(1);
currentRowData.addElement(rs.getString(2);
currentRowData.addElement(rs.getString(3);
currentRowData.addElement(rs.getDouble(4);
return curreentRowData;
}