From f433408735170f5626be104716e330c83ce66b7e Mon Sep 17 00:00:00 2001 From: Soka_jplr Date: Tue, 14 May 2024 17:46:43 -0600 Subject: [PATCH] iplementacion --- Base/universidad.sql | 6 +++ .../src/main/java/mx/uv/Controller/DAO.java | 2 + .../java/mx/uv/Controller/DAORegistro.java | 45 +++++++++++++++++++ .../src/main/java/mx/uv/Model/Registro.java | 5 +++ 4 files changed, 58 insertions(+) create mode 100644 backend/src/main/java/mx/uv/Controller/DAORegistro.java create mode 100644 backend/src/main/java/mx/uv/Model/Registro.java diff --git a/Base/universidad.sql b/Base/universidad.sql index 7cfc73f..692800f 100644 --- a/Base/universidad.sql +++ b/Base/universidad.sql @@ -20,6 +20,12 @@ create table alumno( correo varchar(40) ); +create table registro( + id integer auto_increment primary key, + matricula varchar(40), + descripcion varchar(100) +); + drop table examen; create table examen( diff --git a/backend/src/main/java/mx/uv/Controller/DAO.java b/backend/src/main/java/mx/uv/Controller/DAO.java index d10b172..3fc8211 100644 --- a/backend/src/main/java/mx/uv/Controller/DAO.java +++ b/backend/src/main/java/mx/uv/Controller/DAO.java @@ -1,6 +1,7 @@ package mx.uv.Controller; import java.sql.*; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -160,6 +161,7 @@ public class DAO { while (rs.next()) { alumno = new Alumno(rs.getInt(1), rs.getString(2), rs.getString(3),rs.getString(4), rs.getString(5),rs.getString(6),rs.getString(7),rs.getString(8),rs.getString(9)); } + DAORegistro.registrar(alumno," Inicio SesiĆ³n ", LocalDateTime.now()); } catch (Exception e) { System.out.println(e); } finally { diff --git a/backend/src/main/java/mx/uv/Controller/DAORegistro.java b/backend/src/main/java/mx/uv/Controller/DAORegistro.java new file mode 100644 index 0000000..8c48915 --- /dev/null +++ b/backend/src/main/java/mx/uv/Controller/DAORegistro.java @@ -0,0 +1,45 @@ +package mx.uv.Controller; + +import java.time.LocalDateTime; +import java.sql.*; + +import mx.uv.Model.Alumno; + +public class DAORegistro { + private static Conexion cn = Conexion.getInstance(); + + public static void registrar(Alumno alumno, String descripcion, LocalDateTime day) { + PreparedStatement stm = null; + Connection conn = null; + conn = cn.conectar(); + try { + String sql = "INSERT INTO `registro`(`matricula`,`descripcion`)VALUES(?,?);"; + stm = (PreparedStatement) conn.prepareStatement(sql); + stm.setString(1, alumno.getMatricula()); + stm.setString(2, descripcion + day); + stm.executeUpdate(); + } catch (Exception e) { + System.out.println(e); + } finally { + cerrarConexiones(stm,conn); + } + } + + 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); + } + } + +} diff --git a/backend/src/main/java/mx/uv/Model/Registro.java b/backend/src/main/java/mx/uv/Model/Registro.java new file mode 100644 index 0000000..cf7bc25 --- /dev/null +++ b/backend/src/main/java/mx/uv/Model/Registro.java @@ -0,0 +1,5 @@ +package mx.uv.Model; + +public class Registro { + +}