diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java b/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java new file mode 100644 index 0000000..0816966 --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAO_Administrador.java @@ -0,0 +1,129 @@ +package mx.uv.Controller; + +import java.sql.*; +import java.util.ArrayList; +import java.util.List; + +import mx.uv.Model.Administrador; + + + + +public class DAO_Administrador{ + private static Conexion cn = Conexion.getInstance(); + + public static List dameAministradores(){ + Statement stm = null; + ResultSet rs = null; + Connection conn = null; + List resultado = new ArrayList<>(); + + conn = cn.conectar(); + + try { + String sql = "SELECT * from administrador"; + stm = conn.createStatement(); + rs = stm.executeQuery(sql); + while (rs.next()) { + Administrador u = new Administrador(rs.getInt(1), rs.getString(2), rs.getString(3),rs.getString(4),rs.getString(5)); + resultado.add(u); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return resultado; + } + + public boolean agregarAdministrador(Administrador administrador){ + PreparedStatement stm = null; + Connection conn = null; + boolean msj= false; + + conn = cn.conectar(); + + try{ + String sql ="INSERT INTO `administrador` (`matricula`,`contrasena`, `nombre`, `apellido`) VALUES(?,?,?,?);"; + stm = (PreparedStatement) conn.prepareStatement(sql); + stm.setString(1, administrador.getMatricula()); + stm.setString(2, administrador.getContrasena()); + stm.setString(3, administrador.getNombre()); + stm.setString(4, administrador.getNombre()); + stm.setString(5, administrador.getApellido()); + + + + }catch(Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm,conn); + } + return msj; + } + + private static void cerrarConexiones(PreparedStatement stm,Connection conn) { + if (stm != null) { + try { + stm.close(); + } catch (Exception e) { + System.out.println(e); + } + stm = null; + } + try { + conn.close(); + cn.cerrarConexion(); + } catch (Exception e) { + System.out.println(e); + } + } + + public static boolean eliminarAdministrador(int idAdministrador){ + return false; + } + + public static boolean editarAdministrador(Administrador administrador){ + PreparedStatement stm = null; + Connection conn = null; + boolean verificacion =false; + conn = cn.conectar(); + + try{ + String sql ="UPDATE `administrador` SET `matricula` = '"+administrador.getMatricula()+"',`contrasena` = '"+administrador.getContrasena()+"',`nombre` = '"+administrador.getNombre()+"',`apellido` = '"+administrador.getApellido()+"' WHERE `id` = '"+administrador.getId()+"';"; + stm = conn.prepareStatement(sql); + stm.executeUpdate(); + verificacion = true; + }catch (SQLException ex) { + System.err.println(ex); + }finally{ + cerrarConexiones(stm, conn); + cn.cerrarConexion(); + } + return verificacion; + } + + public static Administrador administradorIniciado(String matricula, String contrasena){ + ResultSet rs = null; + Connection conn = null; + Administrador administrador =null; + + conn = cn.conectar(); + + try { + String sql = "SELECT * FROM administrador WHERE matricula = ? AND contrasena = ?"; + PreparedStatement stmt = conn.prepareStatement(sql); + stmt.setString(1, matricula); + stmt.setString(2, contrasena); + rs = stmt.executeQuery(); + while (rs.next()) { + administrador = new Administrador(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getString(5)); + } + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(null, conn); + } + return administrador; + } +} \ No newline at end of file diff --git a/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java b/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java index fbe6983..9df5267 100644 --- a/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java +++ b/backend/src/main/java/mx/uv/Controller/DAO_Carrrera.java @@ -43,7 +43,7 @@ public class DAO_Carrrera{ conn = cn.conectar(); try{ - String sql ="INSERT INTO `carrera` (`area`,`nombre`, `modalidad`, `campus`, `costo`) VALUES(?,?,?,?);"; + String sql ="INSERT INTO `carrera` (`area`,`nombre`, `modalidad`, `campus`, `costo`) VALUES(?,?,?,?,?);"; stm = (PreparedStatement) conn.prepareStatement(sql); stm.setString(1, carrera.getArea()); stm.setString(2, carrera.getNombre()); @@ -101,6 +101,6 @@ public class DAO_Carrrera{ } return verificacion; } - + } \ No newline at end of file