primer commit
This commit is contained in:
commit
c07c05b7dd
21
.classpath
Normal file
21
.classpath
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="module" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry including="**/*.java" kind="src" output="target/classes" path="src">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="optional" value="true"/>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
</attributes>
|
||||||
|
</classpathentry>
|
||||||
|
<classpathentry kind="output" path="target/classes"/>
|
||||||
|
</classpath>
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/bin/
|
||||||
|
*.class
|
||||||
23
.project
Normal file
23
.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>aadd_act2_2</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
||||||
14
.settings/org.eclipse.jdt.core.prefs
Normal file
14
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -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
|
||||||
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
26
pom.xml
Normal file
26
pom.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>aadd_act1_12</groupId>
|
||||||
|
<artifactId>aadd_act1_12</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>9.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>24</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
186
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
186
src/es/palomafp/aadd/inm/GestorMapaMundi.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/es/palomafp/aadd/inm/vo/Continente.java
Normal file
35
src/es/palomafp/aadd/inm/vo/Continente.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
52
src/es/palomafp/aadd/inm/vo/Pais.java
Normal file
52
src/es/palomafp/aadd/inm/vo/Pais.java
Normal file
@ -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";
|
||||||
|
}
|
||||||
|
}
|
||||||
4
target/classes/META-INF/MANIFEST.MF
Normal file
4
target/classes/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Build-Jdk-Spec: 25
|
||||||
|
Created-By: Maven Integration for Eclipse
|
||||||
|
|
||||||
@ -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
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>aadd_act1_12</groupId>
|
||||||
|
<artifactId>aadd_act1_12</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>9.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>24</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
Loading…
Reference in New Issue
Block a user