commit c07c05b7dd7ded3a5a979b71d7462f47ccc04bd8 Author: Isidoro Nevares Martín Date: Fri Oct 31 14:53:06 2025 +0100 primer commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..542b101 --- /dev/null +++ b/.classpath @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e618407 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/bin/ +*.class \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..01f109f --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + aadd_act2_2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..832915d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,14 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=24 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=24 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=24 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..47133e7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + aadd_act1_12 + aadd_act1_12 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 9.5.0 + + + + src + + + maven-compiler-plugin + 3.13.0 + + 24 + + + + + \ No newline at end of file diff --git a/src/es/palomafp/aadd/inm/GestorMapaMundi.java b/src/es/palomafp/aadd/inm/GestorMapaMundi.java new file mode 100644 index 0000000..3578233 --- /dev/null +++ b/src/es/palomafp/aadd/inm/GestorMapaMundi.java @@ -0,0 +1,186 @@ +package es.palomafp.aadd.inm; + +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Scanner; + +import es.palomafp.aadd.inm.vo.Continente; +import es.palomafp.aadd.inm.vo.Pais; + +/** + * + * GestorInstitutoXML: Clase que procesa un fichero XML de un instituto + * utilizando Jackson + * + * @author Isidoro Nevares Martín - IES Virgen de la Paloma + * @date 26 sept 2025 + */ + +public class GestorMapaMundi { + private static final String NOMBRE_BBDD = "Mapamundi"; + + public static void main(String[] args) { + GestorMapaMundi gestor = new GestorMapaMundi(); + + Scanner scanner = new Scanner(System.in); // Crear el scanner + + System.out.println("Introduce una opción de procesamiento sobre Mapa Mundi."); + System.out.println("Opción 1: Consultar el país con código 107."); + System.out.println("Opción 2: Añadir nuevo continente."); + System.out.println("Opción 3: Actualizar el país con código 107. capital -> Capital City."); + System.out.println("Opción 4: Eliminar el continente con código 02."); + System.out.println("Opción 5: Acceso a información de metadatos de la BBDD."); + String opcion = scanner.nextLine(); // Leer una opción introducida. + + Pais pais = null; + switch (opcion) { + case "1": + System.out.println("Opción 1: Consultar el país con código 107."); + pais = gestor.consultarPais(107); + System.out.println(pais); + break; + case "2": + System.out.println("Opción 2: Añadir nuevo continente."); + Continente continente = new Continente(); + continente.setCodigo("06"); + continente.setNombre("Antártida"); + gestor.anyadirContinente(continente); + break; + case "3": + System.out.println("Opción 3: Actualizar el país con código 107. capital -> Capital City."); + pais = gestor.consultarPais(107); + pais.setCapital("Capital City"); + gestor.actualizarPais(pais); + break; + case "4": + System.out.println("Opción 4: Eliminar el continente con código 02."); + gestor.eliminarContinente("02"); + break; + case "5": + System.out.println("Opción 5: Acceso a información de metadatos de la BBDD."); + gestor.imprimirInformaciónMetadatosBBDD(); + break; + } + + scanner.close(); + } + + private Pais consultarPais(int i) { + Pais pais = null; + Connection conexion = getConexionBBDD(); + try (Statement statement = conexion.createStatement()) { + ResultSet resultado = null; + resultado = statement.executeQuery("select * FROM T_PAIS tp join T_CONTINENTE tc " + + " on tp.cod_continente = tc.codigo where tp.identificador = " + i); + + if (resultado.next()) { + pais = new Pais(); + pais.setIdentificador(resultado.getInt("identificador")); + pais.setNombre(resultado.getString("nombre_pais")); + pais.setCapital(resultado.getString("capital")); + + Continente continente = new Continente(); + continente.setCodigo(resultado.getString("codigo")); + continente.setNombre(resultado.getString("nombre_continente")); + + pais.setContinente(continente); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return pais; + } + + private void anyadirContinente(Continente continente) { + Connection conexion = getConexionBBDD(); + try (Statement statement = conexion.createStatement()) { + String sentenciaSql = "insert into T_CONTINENTE (codigo, nombre_continente) " + + "values ('" + continente.getCodigo() + "', '" + continente.getNombre() + "')"; + System.out.println("Sentencia SQL a ejecutar: " + sentenciaSql); + statement.executeUpdate(sentenciaSql); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void actualizarPais(Pais pais) { + Connection conexion = getConexionBBDD(); + try (Statement statement = conexion.createStatement()) { + String sentenciaSql = "UPDATE T_PAIS " + + "set capital = '" + pais.getCapital() + "' where identificador = " + pais.getIdentificador(); + System.out.println("Sentencia SQL a ejecutar: " + sentenciaSql); + statement.executeUpdate(sentenciaSql); + + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + private void eliminarContinente(String codigoContinente) { + Connection conexion = getConexionBBDD(); + try (Statement statement = conexion.createStatement()) { + String sentenciaSql = "delete from T_PAIS where cod_continente = " + codigoContinente; + System.out.println("Sentencia SQL a ejecutar: " + sentenciaSql); + statement.executeUpdate(sentenciaSql); + sentenciaSql = "delete from T_CONTINENTE where codigo = " + codigoContinente; + System.out.println("Sentencia SQL a ejecutar: " + sentenciaSql); + statement.executeUpdate(sentenciaSql); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + private void imprimirInformaciónMetadatosBBDD() { + Connection conexion = getConexionBBDD(); + + DatabaseMetaData metaData; + try { + metaData = conexion.getMetaData(); + // Obtener tablas de la base de datos Mapamundi + ResultSet tablas = metaData.getTables(NOMBRE_BBDD, null, "%", new String[]{"TABLE"}); + while (tablas.next()) { + String nombreTabla = tablas.getString("TABLE_NAME"); + System.out.println(" - " + nombreTabla); + + // Obtener columnas de cada tabla, así como los tipo de cada columna + ResultSet columnas = metaData.getColumns(null, null, nombreTabla, "%"); + while (columnas.next()) { + String nombreColumna = columnas.getString("COLUMN_NAME"); + String tipo = columnas.getString("TYPE_NAME"); + int tamaño = columnas.getInt("COLUMN_SIZE"); + System.out.printf(" Columna: %-20s Tipo: %-10s Tamaño: %d%n", nombreColumna, tipo, tamaño); + } + columnas.close(); + } + tablas.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + } + + private Connection getConexionBBDD() { + Connection conexion = null; + String driver = "com.mysql.cj.jdbc.Driver"; + String url = "jdbc:mysql://192.168.1.35:3306/"+ NOMBRE_BBDD; + String usuario = "root"; + String password = "mysql_123"; + try { + Class.forName(driver); + + conexion = DriverManager.getConnection(url, usuario, password); + } catch (SQLException | ClassNotFoundException e) { + e.printStackTrace(); + } + + return conexion; + } + +} diff --git a/src/es/palomafp/aadd/inm/vo/Continente.java b/src/es/palomafp/aadd/inm/vo/Continente.java new file mode 100644 index 0000000..6c8e548 --- /dev/null +++ b/src/es/palomafp/aadd/inm/vo/Continente.java @@ -0,0 +1,35 @@ +package es.palomafp.aadd.inm.vo; + +/** + * Continente: Clase que se encarga de almacenar información de un Continente. + * + * @author: Isidoro Nevares Martín (IES Virgen de la Paloma) + * @date: 2 oct 2025 + */ +public class Continente { + + private String codigo; + private String nombre; + + @Override + public String toString() { + return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]"; + } + + public String getCodigo() { + return codigo; + } + + public void setCodigo(String codigo) { + this.codigo = codigo; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + +} diff --git a/src/es/palomafp/aadd/inm/vo/Pais.java b/src/es/palomafp/aadd/inm/vo/Pais.java new file mode 100644 index 0000000..ae2e027 --- /dev/null +++ b/src/es/palomafp/aadd/inm/vo/Pais.java @@ -0,0 +1,52 @@ +package es.palomafp.aadd.inm.vo; + +/** + * Pais: Clase que se encarga de almacenar información de un País. + * + * @author: Isidoro Nevares Martín (IES Virgen de la Paloma) + * @date: 2 oct 2025 + */ +public class Pais { + private int identificador; + private String nombre; + private String capital; + private Continente continente; + + public int getIdentificador() { + return identificador; + } + + public void setIdentificador(int identificador) { + this.identificador = identificador; + } + + public String getNombre() { + return nombre; + } + + public void setNombre(String nombre) { + this.nombre = nombre; + } + + public String getCapital() { + return capital; + } + + public void setCapital(String capital) { + this.capital = capital; + } + + public Continente getContinente() { + return continente; + } + + public void setContinente(Continente continente) { + this.continente = continente; + } + + @Override + public String toString() { + return "Pais [identificador=" + identificador + ", nombre=" + nombre + ", capital=" + capital + ", continente=" + + continente + "]\n"; + } +} diff --git a/target/classes/META-INF/MANIFEST.MF b/target/classes/META-INF/MANIFEST.MF new file mode 100644 index 0000000..a297ac5 --- /dev/null +++ b/target/classes/META-INF/MANIFEST.MF @@ -0,0 +1,4 @@ +Manifest-Version: 1.0 +Build-Jdk-Spec: 25 +Created-By: Maven Integration for Eclipse + diff --git a/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.properties b/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.properties new file mode 100644 index 0000000..419ed7d --- /dev/null +++ b/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.properties @@ -0,0 +1,7 @@ +#Generated by Maven Integration for Eclipse +#Fri Oct 31 13:22:38 CET 2025 +artifactId=aadd_act1_12 +groupId=aadd_act1_12 +m2e.projectLocation=C\:\\Users\\ineva\\INM\\Personal\\Trabajo\\00-Educaci\u00F3n - CM\\10-Curso 2025-2026\\02-Acceso de datos -DAM2\\workspace\\aadd_act2_2 +m2e.projectName=aadd_act2_2 +version=0.0.1-SNAPSHOT diff --git a/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.xml b/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.xml new file mode 100644 index 0000000..47133e7 --- /dev/null +++ b/target/classes/META-INF/maven/aadd_act1_12/aadd_act1_12/pom.xml @@ -0,0 +1,26 @@ + + 4.0.0 + aadd_act1_12 + aadd_act1_12 + 0.0.1-SNAPSHOT + + + + com.mysql + mysql-connector-j + 9.5.0 + + + + src + + + maven-compiler-plugin + 3.13.0 + + 24 + + + + + \ No newline at end of file