注册 登录
编程论坛 JAVA论坛

这两段结果集的代码运行后为什么有不同的结果?

mojiethebest 发布于 2019-12-13 15:15, 1487 次点击
说明: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;
}
0 回复
1