commit
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-26">
|
||||||
|
<attributes>
|
||||||
|
<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 excluding="**" kind="src" output="target/classes" path="config">
|
||||||
|
<attributes>
|
||||||
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="optional" 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>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>aadd_conect02</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>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=26
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=26
|
||||||
|
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=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||||
|
org.eclipse.jdt.core.compiler.release=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.source=26
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
sgdb.clase.driver=com.mysql.cj.jdbc.Driver
|
||||||
|
sgdb.conexion.url=jdbc:mysql://10.100.11.141:3306/
|
||||||
|
bbdd.nombre=Mapa_Mundi
|
||||||
|
bbdd.usuario=root
|
||||||
|
bbdd.clave=root
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
|||||||
|
sgdb.clase.driver=com.mysql.cj.jdbc.Driver
|
||||||
|
sgdb.conexion.url=jdbc:mysql://10.100.11.141:3306/
|
||||||
|
bbdd.nombre=Mapa_Mundi
|
||||||
|
bbdd.usuario=root
|
||||||
|
bbdd.clave=root
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<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_conect02</groupId>
|
||||||
|
<artifactId>aadd_conect02</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>26.10.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>config</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>26</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
module aadd_conect02 {
|
||||||
|
requires java.sql;
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.palomafp.aadd.lmga;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
import org.palomafp.aadd.lmga.service.PaisService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* AppPrincipal: Clase que realiza ....
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 28 oct 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AppPrincipal {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AppPrincipal app = new AppPrincipal();
|
||||||
|
|
||||||
|
app.realizarTratamientoPaises();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void realizarTratamientoPaises() {
|
||||||
|
PaisService paisService = new PaisService();
|
||||||
|
|
||||||
|
// 1. Imprimir lista Paises
|
||||||
|
List<Pais> listaPaises = paisService.obtenerListaPaises();
|
||||||
|
for (Pais pais : listaPaises) {
|
||||||
|
System.out.println(pais);
|
||||||
|
}
|
||||||
|
System.out.println("----------Fin---obtenerListaPaises-------------");
|
||||||
|
|
||||||
|
// 2. Imprimir país 152
|
||||||
|
int idPais = 152;
|
||||||
|
Pais pais = paisService.obtenerPaisPorID(idPais);
|
||||||
|
System.out.println(pais);
|
||||||
|
System.out.println("--------Fin---obtenerPaisPorIdentificador---------------");
|
||||||
|
|
||||||
|
// Se realizan las operaciones si existe el país.
|
||||||
|
if (pais != null) {
|
||||||
|
// 3. Borrar Paises 152
|
||||||
|
paisService.borrarPais(idPais);
|
||||||
|
System.out.println("--------Fin---borrarPais---------------");
|
||||||
|
|
||||||
|
// 4. Insertar Paises 152
|
||||||
|
paisService.insertarPais(pais);
|
||||||
|
System.out.println("---------Fin---insertarPais--------------");
|
||||||
|
|
||||||
|
// 5. Actualizar País - Capital City
|
||||||
|
pais.setCapital("Capital City");
|
||||||
|
paisService.actualizarPais(pais);
|
||||||
|
System.out.println("---------Fin---actualizarPais--------------");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.palomafp.aadd.lmga.dao;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface IPaisDAO {
|
||||||
|
List<Pais> obtenerListaPaises();
|
||||||
|
Pais obtenerPaisPorIdentificador(int idPais);
|
||||||
|
void insertarPais(Pais pais);
|
||||||
|
void actualizarPais(Pais pais);
|
||||||
|
void borrarPais(int idPais);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
package org.palomafp.aadd.lmga.dao.impl;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.lmga.model.Continente;
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
|
||||||
|
public class PaisDaoJDBC implements IPaisDAO {
|
||||||
|
private final Connection conexion;
|
||||||
|
|
||||||
|
public PaisDaoJDBC(Connection conexion) {
|
||||||
|
this.conexion = conexion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Pais> obtenerListaPaises() {
|
||||||
|
List<Pais> listaPaises = new ArrayList<Pais>();
|
||||||
|
|
||||||
|
String sentenciaSQL = """
|
||||||
|
SELECT *
|
||||||
|
FROM T_PAIS p JOIN T_CONTINENTE c
|
||||||
|
ON p.cod_continente=c.codigo
|
||||||
|
""";
|
||||||
|
// System.out.println(sentenciaSQL);
|
||||||
|
try (Statement sentencia = conexion.createStatement();
|
||||||
|
ResultSet resultados = sentencia.executeQuery(sentenciaSQL);) {
|
||||||
|
while (resultados.next()) {
|
||||||
|
int identificador = resultados.getInt("p.identificador");
|
||||||
|
String nombrePais = resultados.getString("p.nombre_pais");
|
||||||
|
String capital = resultados.getString("p.capital");
|
||||||
|
String codigoContinente = resultados.getString("c.codigo");
|
||||||
|
String nombreContinente = resultados.getString("c.nombre_continente");
|
||||||
|
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombre(nombreContinente);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
listaPaises.add(pais);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Pais obtenerPaisPorIdentificador(int idPais) {
|
||||||
|
Pais pais = null;
|
||||||
|
|
||||||
|
String sentenciaSQL = """
|
||||||
|
SELECT *
|
||||||
|
FROM T_PAIS p JOIN T_CONTINENTE c
|
||||||
|
ON p.cod_continente=c.codigo
|
||||||
|
WHERE p.identificador = %d
|
||||||
|
""";
|
||||||
|
sentenciaSQL = String.format(sentenciaSQL, idPais);
|
||||||
|
// System.out.println(sentenciaSQL);
|
||||||
|
try (Statement sentencia = conexion.createStatement();
|
||||||
|
ResultSet resultados = sentencia.executeQuery(sentenciaSQL);) {
|
||||||
|
if (resultados.next()) {
|
||||||
|
int identificador = resultados.getInt("p.identificador");
|
||||||
|
String nombrePais = resultados.getString("p.nombre_pais");
|
||||||
|
String capital = resultados.getString("p.capital");
|
||||||
|
String codigoContinente = resultados.getString("c.codigo");
|
||||||
|
String nombreContinente = resultados.getString("c.nombre_continente");
|
||||||
|
|
||||||
|
pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
|
||||||
|
Continente continente = new Continente();
|
||||||
|
continente.setCodigo(codigoContinente);
|
||||||
|
continente.setNombre(nombreContinente);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertarPais(Pais pais) {
|
||||||
|
String sentenciaSQL = """
|
||||||
|
INSERT INTO T_PAIS (identificador, nombre_pais, capital, cod_continente)
|
||||||
|
VALUES (%d, '%s', '%s', '%s')
|
||||||
|
""";
|
||||||
|
sentenciaSQL = String.format(sentenciaSQL, pais.getIdentificador(), pais.getNombre(), pais.getCapital(),
|
||||||
|
pais.getContinente().getCodigo());
|
||||||
|
// System.out.println(sentenciaSQL);
|
||||||
|
try (Statement sentencia = conexion.createStatement();) {
|
||||||
|
sentencia.executeUpdate(sentenciaSQL);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actualizarPais(Pais pais) {
|
||||||
|
String sentenciaSQL = """
|
||||||
|
UPDATE T_PAIS
|
||||||
|
SET nombre_pais = '%s',
|
||||||
|
capital = '%s',
|
||||||
|
cod_continente= '%s'
|
||||||
|
WHERE identificador= %d
|
||||||
|
""";
|
||||||
|
sentenciaSQL = String.format(sentenciaSQL, pais.getNombre(), pais.getCapital(),
|
||||||
|
pais.getContinente().getCodigo(), pais.getIdentificador());
|
||||||
|
// System.out.println(sentenciaSQL);
|
||||||
|
try (Statement sentencia = conexion.createStatement();) {
|
||||||
|
sentencia.executeUpdate(sentenciaSQL);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void borrarPais(int idPais) {
|
||||||
|
String sentenciaSQL = """
|
||||||
|
DELETE FROM T_PAIS
|
||||||
|
WHERE identificador = %d
|
||||||
|
""";
|
||||||
|
sentenciaSQL = String.format(sentenciaSQL, idPais);
|
||||||
|
// System.out.println(sentenciaSQL);
|
||||||
|
try (Statement sentencia = conexion.createStatement();) {
|
||||||
|
sentencia.executeUpdate(sentenciaSQL);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package org.palomafp.aadd.lmga.gestores;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class GestorConexionesBBDD {
|
||||||
|
|
||||||
|
private GestorConexionesBBDD() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection obtenerConexion() {
|
||||||
|
Connection conexion = null;
|
||||||
|
try {
|
||||||
|
Class.forName(GestorConfiguracion.getClaseDriver());
|
||||||
|
|
||||||
|
String urlConexionCompleta = GestorConfiguracion.getConexionURL() + GestorConfiguracion.getNombreBBDD();
|
||||||
|
String usuarioBBDD=GestorConfiguracion.getUsuarioBBDD();
|
||||||
|
String claveBBDD=GestorConfiguracion.getClaveBBDD();
|
||||||
|
conexion = DriverManager.getConnection(urlConexionCompleta, usuarioBBDD, claveBBDD);
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
throw new RuntimeException("No se ha podido obtener una conexión con el SGDB", e);
|
||||||
|
}
|
||||||
|
return conexion;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package org.palomafp.aadd.lmga.gestores;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class GestorConfiguracion {
|
||||||
|
private static final String RUTA_FICHERO_CONFIGURACION = "application.properties";
|
||||||
|
private static final Properties PROPIEDADES_CONFIGURACION = new Properties();
|
||||||
|
|
||||||
|
|
||||||
|
private GestorConfiguracion() {
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (InputStream inputStream = GestorConfiguracion.class.getClassLoader().getResourceAsStream(RUTA_FICHERO_CONFIGURACION);)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (inputStream == null) {
|
||||||
|
throw new IOException(
|
||||||
|
"No se encuentra "+ RUTA_FICHERO_CONFIGURACION + " en el classpath");
|
||||||
|
}
|
||||||
|
PROPIEDADES_CONFIGURACION.load(inputStream);
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException("No se ha podido cargar el fichero de configuración", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClaseDriver() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("sgdb.clase.driver");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getConexionURL() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("sgdb.conexion.url");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getNombreBBDD() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.nombre");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getUsuarioBBDD() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.usuario");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getClaveBBDD() {
|
||||||
|
return PROPIEDADES_CONFIGURACION.getProperty("bbdd.clave");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package org.palomafp.aadd.lmga.model;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String 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;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.palomafp.aadd.lmga.model;
|
||||||
|
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package org.palomafp.aadd.lmga.service;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.lmga.dao.IPaisDAO;
|
||||||
|
import org.palomafp.aadd.lmga.dao.impl.PaisDaoJDBC;
|
||||||
|
import org.palomafp.aadd.lmga.gestores.GestorConexionesBBDD;
|
||||||
|
import org.palomafp.aadd.lmga.model.Pais;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* PaisService: Clase que se encarga de las operaciones de servicio de un Pais (Casos de uso de países).
|
||||||
|
*
|
||||||
|
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||||
|
* @date 29 oct 2026
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PaisService {
|
||||||
|
|
||||||
|
public List<Pais> obtenerListaPaises() {
|
||||||
|
List<Pais> listaPaises = null;
|
||||||
|
|
||||||
|
try (Connection conexion = GestorConexionesBBDD.obtenerConexion();) {
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoJDBC(conexion);
|
||||||
|
listaPaises = iPaisDAO.obtenerListaPaises();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return listaPaises;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Pais obtenerPaisPorID(int idPais) {
|
||||||
|
Pais pais = null;
|
||||||
|
|
||||||
|
try (Connection conexion = GestorConexionesBBDD.obtenerConexion();) {
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoJDBC(conexion);
|
||||||
|
pais = iPaisDAO.obtenerPaisPorIdentificador(idPais);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return pais;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insertarPais(Pais pais) {
|
||||||
|
|
||||||
|
try (Connection conexion = GestorConexionesBBDD.obtenerConexion();) {
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoJDBC(conexion);
|
||||||
|
iPaisDAO.insertarPais(pais);
|
||||||
|
;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void actualizarPais(Pais pais) {
|
||||||
|
|
||||||
|
try (Connection conexion = GestorConexionesBBDD.obtenerConexion();) {
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoJDBC(conexion);
|
||||||
|
iPaisDAO.actualizarPais(pais);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void borrarPais(int idPais) {
|
||||||
|
|
||||||
|
try (Connection conexion = GestorConexionesBBDD.obtenerConexion()) {
|
||||||
|
|
||||||
|
IPaisDAO iPaisDAO = new PaisDaoJDBC(conexion);
|
||||||
|
iPaisDAO.borrarPais(idPais);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Java-Version: 26
|
||||||
|
Build-Jdk-Spec: 25
|
||||||
|
Created-By: Maven Integration for Eclipse
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#Generated by Maven Integration for Eclipse
|
||||||
|
#Fri Oct 30 16:19:36 CET 2026
|
||||||
|
artifactId=aadd_conect02
|
||||||
|
groupId=aadd_conect02
|
||||||
|
m2e.projectLocation=C\:\\Users\\alumnoT\\eclipse-workspace\\aadd_conect02
|
||||||
|
m2e.projectName=aadd_conect02
|
||||||
|
version=0.0.1-SNAPSHOT
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<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_conect02</groupId>
|
||||||
|
<artifactId>aadd_conect02</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>26.10.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>src</sourceDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>config</directory>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<release>26</release>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
sgdb.clase.driver=com.mysql.cj.jdbc.Driver
|
||||||
|
sgdb.conexion.url=jdbc:mysql://10.100.11.141:3306/
|
||||||
|
bbdd.nombre=Mapa_Mundi
|
||||||
|
bbdd.usuario=root
|
||||||
|
bbdd.clave=root
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user