public void supprimerPersonne(String nom) throws Exception {
    try {
      // Si la personne n'existe pas
      if (!personne.existe(nom)) {
        throw new Tp5Exception("Impossible de supprimer, la personne " + nom + " n'existe pas.");
      }
      // S'il est le realisateur d'au moins un film
      if (!film.filmDeRealisateur(nom).isEmpty()) {
        throw new Tp5Exception(
            "Impossible de supprimer, la personne " + nom + " a realise au moins un film.");
      }
      // S'il est le realisateur d'au moins une serie
      if (!serie.serieDeRealisateur(nom).isEmpty()) {
        throw new Tp5Exception(
            "Impossible de supprimer, la personne " + nom + " a realise au moins une serie.");
      }
      // S'il a un role dans au moins un film
      if (!roleFilm.rolesDeActeur(nom).isEmpty()) {
        throw new Tp5Exception(
            "Impossible de supprimer, la personne " + nom + " a un role dans au moins un film.");
      }
      // S'il a au moins un role dans au moins un episode d'au moins une serie
      if (!roleEpisode.rolesDeActeur(nom).isEmpty()) {
        throw new Tp5Exception(
            "Impossible de supprimer, la personne " + nom + " a un role dans au moins une series.");
      }

      int nb = personne.enlever(nom);
      cx.commit();
      System.out.println(nb + " personne supprime.");
    } catch (Exception e) {
      cx.rollback();
      throw e;
    }
  }
Example #2
0
 /** @param args */
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   try {
     Connexion conn = new Connexion();
     conn.Connect();
     FilConnexion fil = new FilConnexion(conn);
     fil.start();
     for (int i = 0; i < 5; i++) {
       conn.SendGet();
       System.out.println("GET SENT!");
       Thread.sleep(500);
     }
     fil.interrupt();
     conn.EndConnection();
     System.out.println("FINI!");
   } catch (UnknownHostException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   // new BackToJava();
   catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #3
0
 private void init() throws SQLException {
   stmtEpisodeExiste =
       cx.getConnection()
           .prepareStatement(
               "SELECT * FROM Episode WHERE titreSerie = ? AND anneeSortieSerie = ?"
                   + " AND noSaison = ? AND noEpisode = ?");
   stmtAjouterEpisode =
       cx.getConnection()
           .prepareStatement(
               "INSERT INTO Episode (titre, titreSerie, anneeSortieSerie,"
                   + " noSaison, noEpisode, description, dateDiffusion)"
                   + " VALUES (?, ?, ?, ?, ?, ?, ?)");
 }
 public void ajoutPersonne(String nom, Date dateNaissance, String lieuNaissance, int sexe)
     throws Exception {
   try {
     // Vérifie si la personne existe déjà
     if (personne.existe(nom)) {
       throw new Tp5Exception("Impossible d'ajouter, la personne " + nom + " existe deja.");
     }
     personne.ajouter(nom, dateNaissance, lieuNaissance, sexe);
     cx.commit();
   } catch (Exception e) {
     cx.rollback();
     throw e;
   }
 }
Example #5
0
 /** Test of getConnection method, of class Connexion. */
 @Test
 public void testGetConnection() throws Exception {
   System.out.println("getConnection");
   Connection expResult = null;
   Connection result = Connexion.getConnection();
   assertTrue(expResult != result);
 }
Example #6
0
 private void init() throws SQLException {
   stmGetPersonne = cx.getConnection().prepareStatement("SELECT * FROM Personne WHERE nom = ?");
   stmInsertPersonne =
       cx.getConnection()
           .prepareStatement(
               "INSERT INTO Personne (nom, datenaissance, lieunaissance, sexe) VALUES(?, ?, ?, ?)");
   stmDeletePersonne = cx.getConnection().prepareStatement("DELETE FROM Personne WHERE nom = ?");
   stmtGetRealisateur =
       cx.getConnection()
           .prepareStatement(
               "SELECT * FROM personne WHERE nom IN (SELECT DISTINCT realisateur FROM Film)");
   stmtGetActeurDeSerie =
       cx.getConnection()
           .prepareStatement(
               "SELECT * FROM personne WHERE nom IN (SELECT DISTINCT nomActeur FROM RoleEpisode WHERE titreSerie = ? AND anneeSortieSerie = ?)");
 }
Example #7
0
 /** Creation d'une instance. Précompilation d'énoncés SQL. */
 public Membre(Connexion cx) throws SQLException {
   this.cx = cx;
   this.stmtExiste =
       cx.getConnection()
           .prepareStatement(
               "select idMembre, nom, telephone, limitePret, nbpret from membre where idmembre = ?");
   this.stmtInsert =
       cx.getConnection()
           .prepareStatement(
               "insert into membre (idmembre, nom, telephone, limitepret, nbpret) "
                   + "values (?,?,?,?,0)");
   this.stmtUpdateIncrNbPret =
       cx.getConnection()
           .prepareStatement("update membre set nbpret = nbPret + 1 where idMembre = ?");
   this.stmtUpdateDecNbPret =
       cx.getConnection()
           .prepareStatement("update membre set nbpret = nbPret - 1 where idMembre = ?");
   this.stmtDelete = cx.getConnection().prepareStatement("delete from membre where idmembre = ?");
 }
Example #8
0
  public int Get_Identifiant(Connection connection, String id) throws Exception {
    CallableStatement cs = null;
    try {
      Connexion cnx = new Connexion();
      cnx.setConnexion();
      connection = cnx.getConnexion();
      cs = connection.prepareCall("{? = call inc_parametre(?)}");
      cs.registerOutParameter(1, Types.INTEGER);
      cs.setString(2, id);
      cs.execute();
      return (cs.getInt(1));

    } catch (Exception e) {
      throw e;
    } finally {
      try {
        if (cs != null) cs.close();
      } catch (Exception e) {
        throw e;
      }
    }
  }
Example #9
0
  /**
   * Enregistrement de la commande dans la BD
   *
   * @return La page web du compte avec le recapitulatif commande
   * @see String
   */
  public String cloturerCommande() {
    Date today = new Date();
    com = new Commande(today, "En cours de traitement", "Paye", connexion.getCli());
    commFacade.create(com);

    for (Entry<Integer, Lignecommande> select : caddie.entrySet()) {

      // ajout coll
      Lignecommande ligneCom = select.getValue();

      ligneCom.setCommande(com);
      ligneCom.setLignecommandePK(
          new LignecommandePK(com.getIdcommande(), ligneCom.getProduit().getIdproduit()));
      com.getLignecommandeCollection().add(ligneCom);

      // create ligne
      licommFacade.create(ligneCom);
      commFacade.edit(com);
    }
    // vider panier
    caddie.clear();
    return "compte";
  }
Example #10
0
 /**
  * Afficher les commandes
  *
  * @return Une liste de toutes les commandes du client connecte
  * @see List
  * @see Commande
  */
 public List<Commande> getAllCommande() {
   return commFacade.findByClient(connexion.getCli());
 }
Example #11
0
 public void fermer() throws SQLException {
   // fermeture de la connexion
   cx.fermer();
 }
Example #12
0
  public void enregistrer_login() {
    String sql,
        nomI,
        prenomI,
        date_naissanceI,
        emailI,
        passwordI1,
        passwordI2,
        adresseI,
        villeI,
        code_postalI,
        telephoneI,
        mobileI,
        id_couleurI,
        type_utilisateurI;

    Connexion maBDD = new Connexion("localhost", "root", "", "autodrive");
    maBDD.seConnecter();
    try {
      nomI = this.nomI.getText();
      prenomI = this.prenomI.getText();
      date_naissanceI = this.date_naissanceI.getText();
      emailI = this.emailI.getText();
      passwordI1 = this.passwordI1.getText();
      passwordI2 = this.passwordI2.getText();
      adresseI = this.adresseI.getText();
      villeI = this.villeI.getText();
      code_postalI = this.code_postalI.getText();
      telephoneI = this.telephoneI.getText();
      mobileI = this.mobileI.getText();

      // moyPaiement=txtmoy.getSelectedText();
      System.out.println(
          nomI
              + " "
              + prenomI
              + " "
              + date_naissanceI
              + ""
              + emailI
              + " "
              + passwordI1
              + " "
              + adresseI
              + " "
              + villeI
              + ""
              + code_postalI
              + " "
              + telephoneI
              + " "
              + mobileI);

      // insertion
      Statement unStatement = maBDD.getConnection().createStatement();
      // ResultSet unResultat = unStatement.executeQuery(sql);
      sql =
          "INSERT INTO utilisateurs (nom,prenom,date_naissance,email,password,adresse,ville,code_postal,telephone,mobile) VALUES ('"
              + this.nomI.getText()
              + "','"
              + this.prenomI.getText()
              + "','"
              + this.date_naissanceI.getText()
              + "','"
              + this.emailI.getText()
              + "','"
              + this.passwordI1.getText()
              + "','"
              + this.adresseI.getText()
              + "','"
              + this.villeI.getText()
              + "','"
              + this.code_postalI.getText()
              + "','"
              + this.telephoneI.getText()
              + "','"
              + this.mobileI.getText()
              + ")";
      unStatement.executeUpdate(sql);
      // System.out.println(sql+" ligne insérée");
      JOptionPane.showMessageDialog(this, "Votre compte à bien été ajouter");
      unStatement.close();
      unStatement.close();

    } catch (SQLException exp) {
      JOptionPane.showMessageDialog(
          null, exp.getMessage(), "ERREUR SUR LA REQUETTE ! ", JOptionPane.ERROR_MESSAGE);
    }
    maBDD.seDeconnecter();
  }
Example #13
0
  public void enregistrer_edit() {

    String sql,
        nom,
        prenom,
        date_naissance,
        email,
        password1,
        password2,
        adresse,
        ville,
        code_postal,
        telephone,
        mobile,
        id_couleur,
        type_utilisateur;

    Connexion maBDD = new Connexion("localhost", "root", "", "autodrive");
    maBDD.seConnecter();
    try {
      nom = this.nom.getText();
      prenom = this.prenom.getText();
      date_naissance = this.date_naissance.getText();
      email = this.email.getText();
      password1 = this.password1.getText();
      password2 = this.password2.getText();
      adresse = this.adresse.getText();
      ville = this.ville.getText();
      code_postal = this.code_postal.getText();
      telephone = this.telephone.getText();
      mobile = this.mobile.getText();

      /*		calendar_id=this.calendar_id.getToolTipText();
      utc_id=this.utc_id.getToolTipText();
      title=this.title.getToolTipText(); */

      // moyPaiement=txtmoy.getSelectedText();
      System.out.println(
          nom
              + " "
              + prenom
              + " "
              + date_naissance
              + ""
              + email
              + " "
              + password1
              + " "
              + adresse
              + " "
              + ville
              + ""
              + code_postal
              + " "
              + telephone
              + " "
              + mobile);

      // insertion
      Statement unStatement = maBDD.getConnection().createStatement();
      // ResultSet unResultat = unStatement.executeQuery(sql);
      sql =
          "UPDATE utilisateurs SET nom = nom, prenom = prenom, date_naissance = date_naissance, email = email, password1 = password, adresse = adresse, ville = ville, code_postal = code_postal, telephone = telephone, mobile = mobile where id_utilisateur = id_utilisateur";

      unStatement.executeUpdate(sql);
      // System.out.println(sql+" ligne insérée");
      JOptionPane.showMessageDialog(this, "Votre compte à bien été modifier");

      unStatement.close();
      unStatement.close();

    } catch (SQLException exp) {
      JOptionPane.showMessageDialog(
          null, exp.getMessage(), "ERREUR SUR LA REQUETTE ! ", JOptionPane.ERROR_MESSAGE);
    }
    maBDD.seDeconnecter();
  }
  public static void InserDonnees(String fichier)
      throws NumberFormatException, IOException, SQLException {

    try {

      Connexion co = new Connexion("postgres", "562662");
      BufferedReader fichier_source = new BufferedReader(new FileReader(fichier));
      String chaine;

      while ((chaine = fichier_source.readLine()) != null) {

        String[] tabChaine = chaine.split("\\|");
        int rep = Integer.parseInt(tabChaine[0]);

        switch (rep) {
          case 10:
            co.ecrireEmballeur(
                tabChaine[1], tabChaine[2], tabChaine[3], tabChaine[4], tabChaine[5]);
            break;

          case 20:
            co.ecrireClient(
                tabChaine[1],
                tabChaine[2],
                tabChaine[3],
                tabChaine[4],
                tabChaine[5],
                tabChaine[6],
                tabChaine[7],
                tabChaine[8],
                tabChaine[9]);
            break;

          case 30:
            co.ecrireProduit(
                tabChaine[1],
                tabChaine[2],
                tabChaine[3],
                tabChaine[4],
                tabChaine[5],
                tabChaine[6],
                tabChaine[7],
                tabChaine[8],
                tabChaine[9]);
            break;

          case 40:
            co.ecrireTransporteur(tabChaine[1], tabChaine[2], tabChaine[3]);
            break;

          case 50:
            co.ecrireDouane(tabChaine[1], tabChaine[2], tabChaine[3], tabChaine[4]);
            break;

          case 60:
            co.ecrireGerant(tabChaine[1], tabChaine[2], tabChaine[3], tabChaine[4]);
            break;
        }
      }
      fichier_source.close();
      co.close();
    } catch (FileNotFoundException e) {
      System.out.println("Le fichier est introuvable !");
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }