Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/kenri89/PROYECTO_UTP_AED_1_1/llms.txt

Use this file to discover all available pages before exploring further.

The dao package is the single point of contact between the application’s in-memory data structures and the SQL Server database. It defines four interfaces — IEstudianteDAO, ICursoDAO, IMatriculaDAO, and IUsuarioDAO — each with a concrete implementation. Every write operation uses PreparedStatement with positional parameters, meaning no SQL is ever built by concatenating user-supplied strings. If the database is unreachable at runtime, each DAO method returns false or an empty list and logs a warning, allowing the GUI to continue working with in-memory state.

ConexionSQL

util.ConexionSQL is the single class responsible for opening JDBC connections. It reads five mandatory keys (plus two TLS flags) from config.properties on the classpath. If the file is absent, built-in defaults are used so that the application can start even without a custom configuration.
# config.properties (src/config.properties)
db.server=localhost
db.port=1433
db.name=iestp_peru_japon
db.user=sa
db.password=1234
db.encrypt=true
db.trustCertificate=true
The JDBC URL is assembled at runtime as:
jdbc:sqlserver://<db.server>:<db.port>;databaseName=<db.name>;encrypt=<db.encrypt>;trustServerCertificate=<db.trustCertificate>;
User credentials (db.user / db.password) are passed separately to DriverManager.getConnection() rather than embedded in the URL string. Properties are cached after the first load so the file is only read once per JVM session.
The JDBC driver in use is mssql-jdbc 13.4.0 (Microsoft’s official SQL Server JDBC driver). Make sure mssql-jdbc-13.4.0.jre11.jar is on the runtime classpath before launching the application.

DAO Interface Overview

Each interface maps to one database table and exposes the minimum operations required by the GUI panels. The table below summarises the relationships:
InterfaceImplementationManaged Entity
IEstudianteDAOEstudianteDAOStudents — Estudiantes table (carnet PK)
ICursoDAOCursoDAOCourses — Cursos table (codigo PK)
IMatriculaDAOMatriculaDAOEnrollments — Matriculas table (carnet + codigo_curso FK pair)
IUsuarioDAOUsuarioDAOUsers / login — usuarios table

IEstudianteDAO

IEstudianteDAO covers the full CRUD lifecycle for the Estudiantes table.
MethodParametersReturnSQL
insertarcarnet, nombre, carrerabooleanINSERT INTO Estudiantes (carnet, nombre, carrera) VALUES (?, ?, ?)
listarList<String[]>SELECT carnet, nombre, carrera FROM Estudiantes
actualizarcarnet, nombre, carrerabooleanUPDATE Estudiantes SET nombre = ?, carrera = ? WHERE carnet = ?
eliminarcarnetbooleanDELETE FROM Estudiantes WHERE carnet = ?
carnet
String
required
Primary key — the student’s registration number (e.g. "2024001"). Must be unique across the Estudiantes table.
nombre
String
required
Full name of the student (up to 100 characters).
carrera
String
required
Degree programme name (up to 100 characters, e.g. "Computación").

ICursoDAO

ICursoDAO manages the course catalogue stored in the Cursos table.
MethodParametersReturnSQL
insertarcodigo, nombre, creditos, semestrebooleanINSERT INTO Cursos (codigo, nombre, creditos, semestre) VALUES (?, ?, ?, ?)
listarList<String[]>SELECT codigo, nombre, creditos, semestre FROM Cursos
actualizarcodigo, nombre, creditos, semestrebooleanUPDATE Cursos SET nombre = ?, creditos = ?, semestre = ? WHERE codigo = ?
eliminarcodigobooleanDELETE FROM Cursos WHERE codigo = ?
codigo
String
required
Primary key — the course code (e.g. "AED101"). Up to 20 characters.
nombre
String
required
Descriptive course title (up to 100 characters).
creditos
int
required
Number of academic credits assigned to the course.
semestre
int
required
Semester number in which the course is taught (typically 1–10).

IMatriculaDAO

IMatriculaDAO records which students are enrolled in which courses. The Matriculas table uses a surrogate auto-increment id, but enrollment uniqueness is enforced by the (carnet, codigo_curso) pair.
MethodParametersReturnSQL
insertarcarnet, codigoCursobooleanINSERT INTO Matriculas (carnet, codigo_curso) VALUES (?, ?)
listarList<String[]>SELECT carnet, codigo_curso FROM Matriculas
eliminarcarnet, codigoCursobooleanDELETE FROM Matriculas WHERE carnet = ? AND codigo_curso = ?
carnet
String
required
Foreign key referencing Estudiantes(carnet).
codigoCurso
String
required
Foreign key referencing Cursos(codigo).

IUsuarioDAO

IUsuarioDAO has a single method used exclusively for login.
MethodParametersReturn
autenticarusername, password, rolSeleccionadoUsuario or null
UsuarioDAO.autenticar() queries usuarios with a case-insensitive username match (LOWER(username) = LOWER(?)). If the database is unavailable or the credentials are not found in the table, it automatically falls back to autenticarFallback(), which checks hardcoded default accounts (admin/1234, secretaria/1234) or delegates student authentication to CuentasEstudiantes.
username
String
required
Login username, matched case-insensitively against the usuarios table.
password
String
required
Plain-text password compared against the stored value after trimming whitespace.
rolSeleccionado
String
required
Role selected in the login form ("Administrador", "Secretaria", or "Estudiante"). Used by the fallback path to route student credentials to CuentasEstudiantes.

listar() Return Convention

All three data-access interfaces share the same listar() return type: List<String[]>. Each element is a String[] whose positions match the column order of the SELECT statement.

EstudianteDAO.listar()

row[0] = carnet
row[1] = nombre
row[2] = carrera

CursoDAO.listar()

row[0] = codigo
row[1] = nombre
row[2] = creditos (String)
row[3] = semestre (String)

MatriculaDAO.listar()

row[0] = carnet
row[1] = codigo_curso
The numeric fields creditos and semestre are stored as String in the array (via String.valueOf(rs.getInt(...))). The caller is responsible for parsing them back to int when constructing domain objects.

Typical Usage Pattern

The application bootstraps each panel by calling listar() once to hydrate the in-memory data structures, then calls insertar, actualizar, or eliminar in response to user actions.
IEstudianteDAO dao = new EstudianteDAO();

// Insert a new student
dao.insertar("2024001", "Ana Ramos", "Computación");

// Load all students from the database into the BST
List<String[]> rows = dao.listar();
for (String[] row : rows) {
    // row[0]=carnet, row[1]=nombre, row[2]=carrera
    arbolEstudiantes.insertar(new Estudiante(row[0], row[1], row[2]));
}

// Update an existing record
dao.actualizar("2024001", "Ana María Ramos", "Computación");

// Remove the record
dao.eliminar("2024001");
boolean return values indicate whether at least one row was affected (executeUpdate() > 0). A false result can mean either a genuine database error or that no matching row existed — check the SLF4J log output to distinguish between the two cases.

Offline / Fallback Behaviour

The SQL Server connection is opportunistic. Every DAO method wraps its logic in a try-with-resources block and catches Exception. On failure it logs a warning at WARN level and returns false / an empty list without throwing. This means:
  • GUI panels continue to function using the in-memory data structures.
  • Any changes made while offline are held in RAM only.
  • PersistenciaAcademica.guardar() can still write those changes to the TSV fallback files on disk.
See the Persistence page for details on the TSV fallback mechanism.

Build docs developers (and LLMs) love