|
发表于 2004-6-19 13:49:51
|
显示全部楼层
不要用vector,早说过了。。。用ArrayList替代。。。
[PHP]
public Collection findAllUser() {
PreparedStatement ps = null;
ResultSet rs = null;
User user = null;
ArrayList list = new ArrayList();
String sql = "SELECT * from user ";
try {
if (con.isClosed()) {
throw new IllegalStateException("unexpected");
}
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while (rs.next()) {
user = new User();
user.setId(rs.getString(1));
user.setEmail(rs.getString(2));
user.setPassword(rs.getString(3));
user.setRole(rs.getString(4));
list.add(user);
}
return list;
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException("unexpected");
} finally {
try {
if (ps != null)
ps.close();
if (rs != null)
rs.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
throw new RuntimeException("unexpected");
}
}
}
[/PHP]
这个以前贴过。。。这只是其中一个方法 |
|