Package ManejoBD

Source Code of ManejoBD.ProfesorBD

/*
* ProfesorBD.java
*
* Created on 11 de noviembre de 2007, 10:10 PM
*
*/

package ManejoBD;

import GeneracionHorarios.Dia;
import GeneracionHorarios.Profesor;
import GeneracionHorarios.Salon;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
*
* @author Fernando
*/
public class ProfesorBD {
   
    /** Creates a new instance of ProfesorBD */
    public ProfesorBD() {
    }

    public static Profesor buscarProfesor(String codigo) throws SQLException {
        String cadBuscar = "SELECT codProfesor,codigo,nombre FROM Profesor WHERE codigo = ?;";
        PreparedStatement pst = AccesoBD.conn.prepareStatement(cadBuscar);
        pst.setString(1,codigo);
        ResultSet rs = pst.executeQuery();
        rs.next();
        Profesor profesorBuscado = new Profesor(rs.getInt(1),rs.getString(2),rs.getString(3));
        pst.close();
        rs.close();
        return profesorBuscado;
    }

    public static void agregarProfesor(Profesor profesor) throws SQLException {
        String cadAgregar = "INSERT INTO Profesor (codigo,nombre) VALUES (?,?);";
        PreparedStatement pst = AccesoBD.conn.prepareStatement(cadAgregar);
        pst.setString(1,profesor.getCodigo());
        pst.setString(2,profesor.getNombre());
        pst.executeUpdate();
        pst.close();
    }

    public static Profesor buscarProfesor(int codProfesor) throws SQLException {
        String cadBuscar = "SELECT codProfesor,codigo,nombre FROM Profesor WHERE codProfesor = ?;";
        PreparedStatement pst = AccesoBD.conn.prepareStatement(cadBuscar);
        pst.setInt(1,codProfesor);
        ResultSet rs = pst.executeQuery();
        rs.next();
        Profesor profesorBuscado = new Profesor(rs.getInt(1),rs.getString(2),rs.getString(3));
        pst.close();
        rs.close();
        return profesorBuscado;
    }
   
}
TOP

Related Classes of ManejoBD.ProfesorBD

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.