1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| Connection connexion = null;
try {
Class.forName(VariableBDDConnexion.pilote).newInstance();
connexion = DriverManager.getConnection(VariableBDDConnexion.adress, VariableBDDConnexion.utilisateur, VariableBDDConnexion.motDePasse);
connexion.setAutoCommit(false);
Statement instruction = connexion.createStatement();
// Création du groupe dans la table groupe
instruction.executeUpdate("INSERT INTO groupe(nom, mode, idProprio) VALUES(\'"
+ groupe.getNom() + "\', \'"
+ groupe.getMode() + "\', "
+ groupe.getIdProprio() + ");");
// Création de utilisateur dans groupe (pour le proprietaire du groupe)
ResultSet result = instruction.executeQuery("SELECT * FROM `groupe` "
+ "WHERE nom='" + groupe.getNom()
+ "'");
String idGroupe = "";
while(result.next()) {
idGroupe = result.getString("id");
}
instruction.executeUpdate("INSERT INTO utilisateurdansgroupe(idGroupe, idUtilisateur, points) VALUES("
+ idGroupe + ", "
+ groupe.getIdProprio() + ", "
+ 0 + ");");
instruction.executeUpdate("INSERT INTO utilisateurdansgroupe(idGroupe, idUtilisateur, points) VALUES("
+ idGroupe + ", "
+ groupe.getIdProprio() + ", "
+ 0 + ");");
// Création de competition dans groupe
for(int i = 0; i<groupe.getListCompetition().size(); i++) {
instruction.executeUpdate("INSERT INTO competitiondansgroupe(idCompetition, idGroupe) VALUES ("
+ groupe.getListCompetition().get(i).getId() + ", "
+ idGroupe + ");");
}
connexion.commit();
} catch (Exception e) {
try{
connexion.rollback();
connexion.close();
}catch(Exception e2){
e.printStackTrace();
}
e.printStackTrace();
throw new ServeurException("Une erreur technique s'est produite, veuillez réessayer plus tard.");
} |
Partager