public boolean leaveEvent(int userID, int eventID) {
    UserModel userM = new UserModel();
    int userId = userM.getUserIdByAccountId(userID);
    Connection con = null;
    try {

      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con =
          DriverManager.getConnection("jdbc:mysql://160.153.16.42:3306/Enterprise_Gym", user, pass);

      PreparedStatement ps2 = null;

      int i = 0;

      String sqlOption = "DELETE from event_has_user where user_iduser=? and event_idevent=?";
      ps2 = con.prepareStatement(sqlOption);
      ps2.setInt(1, userId);
      ps2.setInt(2, eventID);
      i = ps2.executeUpdate();
      con.close();

      if (i == 0) {

        return false;
      } else {
        return true;
      }

    } catch (Exception e) {
      System.out.println("connection to db failed");
      e.printStackTrace();
      return false;
    }
  }
  public Boolean isAttending(int id, int userid) {
    UserModel userM = new UserModel();
    int userId = userM.getUserIdByAccountId(userid);
    Connection con = null;
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con =
          DriverManager.getConnection("jdbc:mysql://160.153.16.42:3306/Enterprise_Gym", user, pass);
      Convertors convertor = new Convertors();
      ResultSet rs = null;
      PreparedStatement ps = null;

      String sqlOption = "SELECT * FROM event_has_user where event_idevent=? and user_iduser=?";

      ps = con.prepareStatement(sqlOption);
      ps.setInt(1, id);
      ps.setInt(2, userId);
      rs = ps.executeQuery();

      if (rs.next()) {
        System.out.println("true");
        return true;
      } else {
        System.out.println("false");
        return false;
      }

    } catch (Exception et) {
      System.out.println("Can't find user" + et);
      return false;
    }
  }
Beispiel #3
0
  public ResultSet getUserByNIP(String nip) throws SQLException {
    ResultSet profile;
    profile = user_model.SelectById(nip);

    if (profile.next()) {
      return profile;
    } else {
      return profile = null;
    }
  }