Example #1
0
 /** Ajoute une BDD (à laquelle est assoicié une ip et un numéro de port) à un client */
 public static Boolean addDbClient(
     Connection con, String email, String bdd, String ip, int port, String user, String pass) {
   Boolean notexist = false;
   int isVip = DatabaseManager.isVipClient(con, email);
   String pwd = DatabaseManager.hisPassword(con, email);
   try {
     if (existClient(con, email)) {
       Statement smt = con.createStatement();
       smt.executeUpdate(
           "INSERT INTO `members`(`email`, `pwd`, `vip`, `ip`, `port`, `bdd`) VALUES ('"
               + email
               + "','"
               + pwd
               + "','"
               + isVip
               + "','"
               + ip
               + "','"
               + port
               + "','"
               + bdd
               + "')");
       smt.executeUpdate(
           "INSERT INTO `mybdd`(`email`, `bdd`, `uname`, `pwd`) VALUES ('"
               + email
               + "','"
               + bdd
               + "','"
               + user
               + "','"
               + pass
               + "')");
       System.out.println(
           "**** email="
               + email
               + " pwd="
               + pwd
               + " vip="
               + isVip
               + " ip="
               + ip
               + " port="
               + port
               + " bdd="
               + bdd);
       notexist = true;
     } else {
       System.out.println("*********************************** PB in addDBClient");
     }
   } catch (SQLException ex) {
     Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
   }
   return notexist;
 }
Example #2
0
 public static void removeModerator(int userID) {
   DatabaseManager dbMan;
   try {
     dbMan = DatabaseManager.getInstance();
     dbMan.removeModerator(userID);
   } catch (SQLException e) {
     e.printStackTrace();
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   }
 }
Example #3
0
  /** Ce main sert uniquement de test, s'y référer pour voir comment appeler les fonctions */
  public static void main(String[] args) {
    try {

      Connection c1 = DatabaseManager.connectionDatabase();
      /*
      ArrayList<Integer> listeID;
      listeID = listOfContainerID(c1);
      int i;
      for (i=0;i<listeID.size();i++){
         System.out.println(listeID.get(i));
      }

      DatabaseManager.addDbClient(c1, "*****@*****.**", "nouvelleBDDSamih", "192.36.26.1", 2563);

      DatabaseManager.createClient(c1, "*****@*****.**", "999999", 0, "bdddeSamih", "123.25.36.2", 25698);
      System.out.println("[email protected] existe ? " + DatabaseManager.existClient(c1, "*****@*****.**"));
      System.out.println("[email protected] a 999999 comme mdp ? " + DatabaseManager.verifConnectionClient(c1, "*****@*****.**", "999999"));
      System.out.println("mot de passe de Samih " + DatabaseManager.hisPassword(c1, "*****@*****.**"));
      DatabaseManager.createClient(c1, "*****@*****.**", "123456", 1, "bdddeYann", "123.25.36.25", 1234);
      DatabaseManager.createClient(c1, "*****@*****.**", "123456", 1, "bdddeYann2", "123.25.36.25", 1234);
      DatabaseManager.addDbClient(c1, "*****@*****.**" ,"nouvelleBDDYann", "192.36.26.1", 2563);
      System.out.println("[email protected] existe ? " + DatabaseManager.existClient(c1, "*****@*****.**"));
      DatabaseManager.deleteClient(c1, "*****@*****.**");
      DatabaseManager.deleteDbClient(c1, "*****@*****.**", "bdddeSamih");
      System.out.println("[email protected] existe ? " + DatabaseManager.existClient(c1, "*****@*****.**"));
       */
      c1.close();

    } catch (SQLException ex) {
      Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
Example #4
0
 public static boolean isPostOwner(int userID, int postID) {
   DatabaseManager dbMan;
   try {
     dbMan = DatabaseManager.getInstance();
     ResultSet result = dbMan.isPostOwner(userID, postID);
     if (result.next()) {
       return true;
     }
     return false;
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return false;
 }
Example #5
0
 public static boolean isLocked(int eventID) {
   DatabaseManager dbMan;
   try {
     dbMan = DatabaseManager.getInstance();
     ResultSet result = dbMan.isLocked(eventID);
     while (result.next()) {
       int isLocked = Integer.parseInt(result.getString("E.isLocked"));
       if (isLocked == 0) {
         return false;
       }
       return true;
     }
     return true;
   } catch (ClassNotFoundException e) {
     e.printStackTrace();
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return false;
 }
Example #6
0
  /**
   * Supprime la ligne de la bdd donnée d'un client, s'il s'agit de sa dernière BDD : on supprime la
   * ligne associée et on rajoute une nouvelle avec : bdd = "_", ip = "_" , et port = 0
   */
  public static Boolean deleteDbClient(Connection con, String email, String bdd) {
    Boolean notexist = false;
    try {
      if (existClient(con, email)) {
        Statement smt = con.createStatement();
        String currentPwd = DatabaseManager.hisPassword(con, email);
        smt.executeUpdate(
            "DELETE FROM members WHERE email = '" + email + "' and bdd = '" + bdd + "'");
        smt.executeUpdate(
            "DELETE FROM mybdd WHERE email = '" + email + "' and bdd = '" + bdd + "'");
        notexist = true;
        if (!existClient(con, email)) {
          DatabaseManager.createClient(con, email, currentPwd, 0, "_", "_", 0);
        }
      }

    } catch (SQLException ex) {
      Logger.getLogger(DatabaseManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    return notexist;
  }