日期:2014-05-19 浏览次数:20795 次
public List<User> list(){ List<User> users=new ArrayList<User>(); Connection conn=DB.createConn(); ResultSet rs=null; String sql="select id,username,password,age,address from user"; PreparedStatement ps=DB.prepare(conn, sql); try{ rs=ps.executeQuery(); User user=new User(); while(rs.next()){ user.setId(rs.getInt(1)); user.setUsername(rs.getString(2)); user.setPassword(rs.getString(3)); user.setAddress(rs.getString(4)); users.add(user); } }catch(Exception e){ e.printStackTrace(); } DB.close(rs); DB.close(ps); DB.close(conn); return users; }