/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.sql.DataSource;
import model.Discipline;
/**
*
* @author DJOUDER
*/
public class DisciplineDAO extends AbstractDataBaseDao {
public DisciplineDAO(DataSource dataSource) {
super(dataSource);
}
/**
* retourne la liste des disciplines contenues dans la BD
* @return liste des disciplines
* @throws DAOException
*/
public List<Discipline> getDisciplines() throws DAOException {
Connection conn = null; //creation connexion comme attribut, variable globale de la classe
Statement stmt = null;
ResultSet result = null;
List<Discipline> disciplines = new ArrayList<Discipline>();
try {
synchronized (dataSource) {
conn = dataSource.getConnection();
}
stmt = conn.createStatement();
String req = "select * from (SELECT DISTINCT NOMDISC FROM EPREUVEEQ UNION SELECT DISTINCT NOMDISC FROM EPREUVEIND)";
System.out.println(req);
result = stmt.executeQuery(req);
// discipline.add(new Discipline());
while (result.next()) {
disciplines.add(new Discipline(result.getString(1)));
}
result.close();
stmt.close();
return disciplines;
} catch (SQLException ex) {
throw new DAOException("problème récupération liste des disciplines", ex);
} finally {
closeConnection(conn);
}
}
}