/** 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; }
/** * 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; }