Пример #1
0
  public ArrayList<Etudiant> selectByIdEc(int idEc) {
    ArrayList<Etudiant> arrayList = new ArrayList<Etudiant>();
    try {
      String sql = SQL_SELECT + " WHERE idEc = ?";
      PreparedStatement pstmt = getConnection().prepareStatement(sql);

      pstmt.setInt(1, idEc);

      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) {
        Utilisateur ut = jdbc_utilisateur.select(rs.getInt("idEtu"));
        Etudiant etu =
            new Etudiant(
                ut, rs.getInt("numEtudiant"), rs.getString("formation"), rs.getInt("idEc"));
        etu.setAttr_int_idUt(ut.getAttr_int_idUt());

        arrayList.add(etu);
      }

      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      System.err.println("SQL error : " + e.getMessage());
    }

    return arrayList;
  }
Пример #2
0
  public Etudiant select(int idEtu) {
    Etudiant etu = null;
    try {
      String sql = SQL_SELECT + " WHERE idEtu = ?";
      PreparedStatement pstmt = getConnection().prepareStatement(sql);

      pstmt.setInt(1, idEtu);

      ResultSet rs = pstmt.executeQuery();

      if (rs.next()) {
        Utilisateur ut = jdbc_utilisateur.select(rs.getInt("idEtu"));
        etu =
            new Etudiant(
                ut, rs.getInt("numEtudiant"), rs.getString("formation"), rs.getInt("idEc"));
        etu.setAttr_int_idUt(ut.getAttr_int_idUt());
      }

      rs.close();
      pstmt.close();
    } catch (SQLException e) {
      System.err.println("SQL error : " + e.getMessage());
    }

    return etu;
  }
Пример #3
0
  public void insert(Etudiant etu) {
    try {
      PreparedStatement pstmt = getConnection().prepareStatement(SQL_INSERT);

      pstmt.setInt(1, etu.getAttr_int_idUt());
      pstmt.setInt(2, etu.getAttr_int_numEtudiant());
      pstmt.setString(3, etu.getAttr_str_formation());
      pstmt.setInt(4, etu.getAttr_int_idEc());

      pstmt.executeUpdate();

      pstmt.close();
    } catch (SQLException e) {
      System.err.println("SQL error : " + e.getMessage());
    }
  }
Пример #4
0
  public void update(Etudiant etu) {
    try {
      String sql = SQL_UPDATE + " WHERE idEtu = ?";
      PreparedStatement pstmt = getConnection().prepareStatement(sql);

      pstmt.setInt(1, etu.getAttr_int_idUt());
      pstmt.setInt(2, etu.getAttr_int_numEtudiant());
      pstmt.setString(3, etu.getAttr_str_formation());
      pstmt.setInt(4, etu.getAttr_int_idEc());
      pstmt.setInt(5, etu.getAttr_int_idUt());

      pstmt.executeUpdate();

      pstmt.close();
    } catch (SQLException e) {
      System.err.println("SQL error : " + e.getMessage());
    }
  }
Пример #5
0
 public void delete(Etudiant etu) {
   delete(etu.getAttr_int_idUt());
 }