コード例 #1
0
  public static boolean insertOneContact(ContactUrgence contact) throws Exception {

    Connection con;
    ConnexionBd connexionBD = new ConnexionBd();
    boolean insertOk = false;
    con = connexionBD.createConnection();

    try {
      String sqlString =
          "insert into contact_urgence "
              + "(id, nom, prenom, courriel, id_relation) "
              + "values ("
              + contact.getId()
              + ", '"
              + contact.getNom()
              + "', '"
              + contact.getPrenom()
              + "', '"
              + contact.getCourriel()
              + "', '"
              + contact.getRelation().getId()
              + "')";

      insertOk = connexionBD.executeSQL(con, sqlString);
      if (!insertOk) {
        System.err.println("***To insert the data row ...." + sqlString);
      }
    } catch (SQLException e) {
      System.err.println("***** Database error at insertOneContact: " + e.getMessage());
    }

    con.close();
    System.out.println("Connection closed");
    return insertOk;
  }
コード例 #2
0
  public static boolean updateContactUrgence(ContactUrgence contact) throws Exception {

    Connection con;
    ConnexionBd connexionBD = new ConnexionBd();
    boolean updateOk = false;
    con = connexionBD.createConnection();

    try {
      String sqlString =
          "Update contact_urgence "
              + " Set nom = "
              + contact.getNom()
              + ", prenom = "
              + contact.getPrenom()
              + ", courriel = "
              + contact.getCourriel()
              + ", id_relation = "
              + contact.getRelation().getId()
              + " Where id = "
              + contact.getId();

      updateOk = connexionBD.executeSQL(con, sqlString);
      if (!updateOk) {
        System.err.println("***To update the data row ...." + sqlString);
      }
    } catch (SQLException e) {
      System.err.println("***** Database error at updateContactUrgence: " + e.getMessage());
    }

    con.close();
    System.out.println("Connection closed");
    return updateOk;
  }
コード例 #3
0
  public static ContactUrgence getOneContact(ContactUrgence contact) throws SQLException {
    Connection con;
    Statement stmt = null;
    ResultSet rs = null;
    ContactUrgence temp = new ContactUrgence();
    ConnexionBd connexionBD = new ConnexionBd();
    con = connexionBD.createConnection();

    try {
      stmt = con.createStatement();
      rs =
          stmt.executeQuery(
              "select * from contact_urgence "
                  + "where prenom = '"
                  + contact.getPrenom()
                  + "' and nom  = '"
                  + contact.getNom()
                  + "' and courriel = '"
                  + contact.getCourriel()
                  + "' and id_relation = "
                  + contact.getRelation().getId());
      if (rs.next()) {
        temp = new ContactUrgence();
        temp.setId(rs.getInt("id"));
        temp.setNom(rs.getString("nom"));
        temp.setPrenom(rs.getString("prenom"));
        temp.setCourriel(rs.getString("courriel"));
        int idRelation = rs.getInt("id_relation");
        // Requète pour récupérer la relation
        rs = stmt.executeQuery("select * from relation where id = " + idRelation);
        if (rs.next()) {
          temp.setRelation(new Relation(rs.getInt("id"), rs.getString("nom")));
        }

      } else {
        System.out.println("***** Le contact n'existe pas.");
      }
    } catch (SQLException e) {
      System.err.println("***** Database error at getOneContact: " + e.getMessage());
    } finally {
      if (rs != null) {
        rs.close();
      }
      if (stmt != null) {
        stmt.close();
      }
    }

    con.close();
    System.out.println("Connection closed");
    System.err.println("***** END getOneContact()");
    return temp;
  }
コード例 #4
0
  public static ArrayList<ContactUrgence> getContactBenevole(int idBenevole) throws Exception {
    Connection con;
    Statement stmt = null;
    ResultSet rs = null;

    ContactUrgence contact = new ContactUrgence();
    ArrayList<ContactUrgence> contacts = new ArrayList<ContactUrgence>();

    ConnexionBd connexionBD = new ConnexionBd();
    con = connexionBD.createConnection();

    try {
      stmt = con.createStatement();
      rs =
          stmt.executeQuery(
              "select c.id, c.prenom, c.nom, c.id_relation from "
                  + "contact_urgence as c, benevole as b, benevole_contact_urgence "
                  + "where b.id = id_benevole "
                  + "and c.id = id_contact_urgence "
                  + "and b.id = "
                  + idBenevole);
      while (rs.next()) {
        contact = new ContactUrgence();
        contact.setId(rs.getInt("id"));
        contact.setNom(rs.getString("nom"));
        contact.setPrenom(rs.getString("prenom"));
        contact.setRelation(new Relation(rs.getInt("id_relation"), ""));
        contacts.add(contact);
      }
    } catch (SQLException e) {
      System.err.println("***** Database error at getContactBenevole: " + e.getMessage());
    } finally {
      if (rs != null) {
        rs.close();
      }
      if (stmt != null) {
        stmt.close();
      }
    }

    con.close();
    System.out.println("Connection closed");
    System.err.println("***** END getContactBenevole()");
    return contacts;
  }