コード例 #1
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;
  }
コード例 #2
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;
  }