Example #1
0
  public void ajoutUtilisateur(Utilisateur util) throws InscriptionException {
    try {
      Context cont = new InitialContext();
      DataSource source = (DataSource) cont.lookup("jdbc/MusicStore");
      connexion = source.getConnection();

      String requeteSQL =
          "INSERT INTO UTILISATEUR"
              + "(NOM, PRENOM, ADR_RUE, ADR_NUMERO, ADR_BOITE, ADR_CODEPOSTAL, ADR_LOCALITE,MAIL,MOTDEPASSE,NUMTEL)"
              + "VALUES(?,?,?,?,?,?,?,LCASE(?),?,?)";
      PreparedStatement prepStat = connexion.prepareStatement(requeteSQL);
      prepStat.setString(1, util.getNom());
      prepStat.setString(2, util.getPrenom());
      prepStat.setString(3, util.getRue());
      prepStat.setInt(4, util.getNumero());
      prepStat.setString(5, util.getBoite());
      prepStat.setInt(6, util.getCodepostal());
      prepStat.setString(7, util.getLocalite());
      prepStat.setString(8, util.getMail());
      prepStat.setString(9, util.getPassword());
      prepStat.setString(10, util.getNumTel());

      prepStat.executeUpdate();

    } catch (SQLIntegrityConstraintViolationException ex) {
      throw new InscriptionException("errorMailUsed");
    } catch (SQLException ex) {
      throw new InscriptionException("sqlException");
    } catch (NamingException ex) {
      throw new InscriptionException("errorNaming");
    } finally {
      try {
        connexion.close();
      } catch (SQLException e) {
        throw new InscriptionException("sqlException");
      }
    }
  }