jsp中如何把ResultSet rs中的结果放入list中再循环取出呢?

2024-12-31 15:13:26
推荐回答(2个)
回答1:

1.

List list = new ArrayList();
try {
rs = ps.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int columnCount = rsmd.getColumnCount();
while(rs.next()){
for(int i=1;i<=columnCount;i++){
//这里也可以放到MAP里面
String columnName = rsmd.getColumnName(i);
Object value = rs.getObject(i);
list.add(columnName+":"+value);
}
}
} catch (Exception e) {
// TODO: handle exception
}

回答2:

while (rs.next())
 {
 rs.getString("seatno")
 }
 rs.close();