예제 #1
0
  @Override
  public ArrayList<User> getAll(int limit, int offset) {
    ArrayList<User> result = new ArrayList<>();
    String sql = "select * from user limit ? offset ?";
    Connection con = new ConnectionPool().getConnection();
    PreparedStatement ps;
    try {
      ps = con.prepareStatement(sql);
      ps = con.prepareStatement("select * from user limit ? offset ?");
      ps.setInt(1, limit);
      ps.setInt(2, offset);
      ResultSet rs = ps.executeQuery();
      while (rs.next()) {
        User user = new User();
        user.setIdUser(rs.getString("idUser"));
        user.setFullName(rs.getString("fullName"));
        user.setEmail(rs.getString("email"));
        user.setUserName(rs.getString("userName"));
        user.setPhone(rs.getString("phone"));
        user.setAddress(rs.getString("address"));
        user.setImg(rs.getString("img"));
        user.setActive(rs.getInt("active"));
        result.add(user);
      }

      rs.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return result;
  }
예제 #2
0
 @Override
 public User getUser(String email) {
   String sql = "select * from user where email = ?";
   Connection c = new ConnectionPool().getConnection();
   User us = new User();
   try {
     PreparedStatement sqlui = c.prepareStatement(sql);
     sqlui.setString(1, email);
     ResultSet rs = sqlui.executeQuery();
     if (rs.next()) {
       us.setIdUser(rs.getString("idUser"));
       us.setFullName(rs.getString("fullName"));
       us.setUserName(rs.getString("userName"));
       us.setEmail(rs.getString("email"));
       us.setImg(rs.getString("img"));
       us.setPhone(rs.getString("phone"));
       us.setAddress(rs.getString("address"));
     }
     rs.close();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return us;
 }