/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.siso.horario.MySqlDAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import pe.siso.horario.Beans.Clase;
import pe.siso.horario.DAO.ClaseDAO;

/**
 *
 * @author fcelestino
 */
public class MySqlClaseDAO implements ClaseDAO {

    @Override
    public ArrayList<Clase> cargarClase() throws Exception {
        ArrayList<Clase> lista = new ArrayList<Clase>();
        String base = "sacoolive3";
        Connection cnx = null;
        try {
            cnx = MySqlDAOFactory.obtenerConexion(base);
            Statement st = cnx.createStatement();

            String query = "SELECT codsec,nomsec FROM seccion ";
            System.out.println(query);
            ResultSet rs = st.executeQuery(query);

            while (rs.next()) {
                Clase clase = new Clase();
                clase.setCodigoClase(rs.getInt("codsec"));
                clase.setNombreClase(rs.getString("nomsec"));
                lista.add(clase);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            cnx.close();
        }
        return lista;
    }

}
