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; }
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; }