Commit inicial
This commit is contained in:
commit
182d91d2f5
41
.classpath
Normal file
41
.classpath
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-23">
|
||||
<attributes>
|
||||
<attribute name="module" 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>
|
||||
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
/bin/
|
||||
*.class
|
||||
/target/
|
||||
34
.project
Normal file
34
.project
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>aaee_ra3_proy3</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.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
<filteredResources>
|
||||
<filter>
|
||||
<id>1772465433562</id>
|
||||
<name></name>
|
||||
<type>30</type>
|
||||
<matcher>
|
||||
<id>org.eclipse.core.resources.regexFilterMatcher</id>
|
||||
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
|
||||
</matcher>
|
||||
</filter>
|
||||
</filteredResources>
|
||||
</projectDescription>
|
||||
2
.settings/org.eclipse.jdt.apt.core.prefs
Normal file
2
.settings/org.eclipse.jdt.apt.core.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.apt.aptEnabled=false
|
||||
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.methodParameters=do not generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=23
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=23
|
||||
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.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=23
|
||||
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
|
||||
112
README.md
Normal file
112
README.md
Normal file
@ -0,0 +1,112 @@
|
||||
# Maven – Resumen rápido
|
||||
|
||||
## ¿Qué es Maven?
|
||||
|
||||
**Apache Maven** es una herramienta de gestión y automatización de proyectos Java.
|
||||
|
||||
Permite compilar, probar, empaquetar y gestionar dependencias de forma automática.
|
||||
Todo se configura mediante un archivo central llamado `pom.xml`.
|
||||
|
||||
---
|
||||
|
||||
## Conceptos básicos
|
||||
|
||||
### POM (Project Object Model)
|
||||
|
||||
Es el archivo `pom.xml`, donde se define:
|
||||
|
||||
* Información del proyecto (`groupId`, `artifactId`, `version`)
|
||||
* Dependencias
|
||||
* Plugins
|
||||
* Configuración de compilación
|
||||
|
||||
Ejemplo básico:
|
||||
```xml
|
||||
<groupId>org.ejemplo</groupId>
|
||||
<artifactId>mi-proyecto</artifactId>
|
||||
<version>1.0.0</version>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Ciclo de vida de Maven (Build Lifecycle)
|
||||
|
||||
El ciclo de vida principal está formado por fases que se ejecutan en orden:
|
||||
|
||||
| Fase | Descripción |
|
||||
| -------- | ------------------------------------------- |
|
||||
| validate | Comprueba que el proyecto es correcto |
|
||||
| compile | Compila el código fuente |
|
||||
| test | Ejecuta los tests |
|
||||
| package | Empaqueta la aplicación (JAR/WAR) |
|
||||
| verify | Verifica que el paquete es válido |
|
||||
| install | Instala el paquete en el repositorio local |
|
||||
| deploy | Publica el paquete en un repositorio remoto |
|
||||
|
||||
Ejemplo de ejecución:
|
||||
```bash
|
||||
mvn clean install
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Repositorios
|
||||
|
||||
Maven descarga las dependencias desde repositorios.
|
||||
|
||||
Tipos:
|
||||
|
||||
* **Local** → en el ordenador (`~/.m2`)
|
||||
* **Central** → repositorio público de Maven
|
||||
* **Remoto** → repositorios privados (Nexus, Artifactory)
|
||||
|
||||
---
|
||||
|
||||
## Dependencias
|
||||
|
||||
Las librerías necesarias para el proyecto se declaran en el `pom.xml`.
|
||||
|
||||
Ejemplo:
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.33</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
Maven descargará automáticamente la librería.
|
||||
|
||||
---
|
||||
|
||||
## Comandos Maven más usados
|
||||
|
||||
| Comando | Función |
|
||||
| ------------- | -------------------------------------------- |
|
||||
| `mvn compile` | Compila el proyecto |
|
||||
| `mvn test` | Ejecuta los tests |
|
||||
| `mvn package` | Genera el JAR/WAR |
|
||||
| `mvn install` | Instala el artefacto en el repositorio local |
|
||||
| `mvn clean` | Elimina la carpeta `target` |
|
||||
|
||||
---
|
||||
|
||||
## Estructura típica de un proyecto Maven
|
||||
```
|
||||
proyecto
|
||||
│
|
||||
├─ pom.xml
|
||||
└─ src
|
||||
├─ main
|
||||
│ ├─ java
|
||||
│ └─ resources
|
||||
└─ test
|
||||
└─ java
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Idea clave
|
||||
|
||||
Maven sigue el principio **"Convention over Configuration"**:
|
||||
si respetas su estructura estándar de proyecto, **necesitas muy poca configuración**.
|
||||
21
pom.xml
Normal file
21
pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<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>org.lapaloma.mapamundi</groupId>
|
||||
<artifactId>aaee_mapamundi</artifactId>
|
||||
<version>mapamundi-0.0.1</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Source: https://mvnrepository.com/artifact/com.mysql/mysql-connector-j -->
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<version>9.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
164
src/main/java/org/lapaloma/mapamundi/AppMapaMundi.java
Normal file
164
src/main/java/org/lapaloma/mapamundi/AppMapaMundi.java
Normal file
@ -0,0 +1,164 @@
|
||||
package org.lapaloma.mapamundi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.lapaloma.mapamundi.dao.IContinenteDAO;
|
||||
import org.lapaloma.mapamundi.dao.impl.ContinenteDaoJDBC;
|
||||
import org.lapaloma.mapamundi.vo.Continente;
|
||||
|
||||
public class AppMapaMundi {
|
||||
|
||||
private Scanner scanner = new Scanner(System.in);
|
||||
private IContinenteDAO continenteDAO = new ContinenteDaoJDBC();
|
||||
|
||||
public static void main(String[] args) {
|
||||
AppMapaMundi app = new AppMapaMundi();
|
||||
app.iniciar();
|
||||
}
|
||||
|
||||
private void iniciar() {
|
||||
|
||||
String opcion = "";
|
||||
|
||||
do {
|
||||
|
||||
mostrarMenu();
|
||||
opcion = scanner.nextLine();
|
||||
|
||||
switch (opcion) {
|
||||
|
||||
case "1":
|
||||
crearContinente();
|
||||
break;
|
||||
|
||||
case "2":
|
||||
buscarPorCodigo();
|
||||
break;
|
||||
|
||||
case "3":
|
||||
buscarPorNombre();
|
||||
break;
|
||||
|
||||
case "4":
|
||||
listarContinentes();
|
||||
break;
|
||||
|
||||
case "5":
|
||||
actualizarContinente();
|
||||
break;
|
||||
|
||||
case "6":
|
||||
borrarContinente();
|
||||
break;
|
||||
|
||||
case "S":
|
||||
case "s":
|
||||
System.out.println("Saliendo de la aplicación...");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Opción no válida");
|
||||
}
|
||||
|
||||
} while (!opcion.equalsIgnoreCase("s"));
|
||||
|
||||
scanner.close();
|
||||
}
|
||||
|
||||
private void mostrarMenu() {
|
||||
|
||||
System.out.println("\n===== MAPA MUNDI - MENÚ =====");
|
||||
System.out.println("1. Crear continente");
|
||||
System.out.println("2. Buscar continente por código");
|
||||
System.out.println("3. Buscar continente por nombre");
|
||||
System.out.println("4. Listar todos los continentes");
|
||||
System.out.println("5. Actualizar continente");
|
||||
System.out.println("6. Borrar continente");
|
||||
System.out.println("S. Salir");
|
||||
System.out.print("Seleccione una opción: ");
|
||||
}
|
||||
|
||||
private void crearContinente() {
|
||||
|
||||
System.out.print("Código del continente: ");
|
||||
String codigo = scanner.nextLine();
|
||||
|
||||
System.out.print("Nombre del continente: ");
|
||||
String nombre = scanner.nextLine();
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigo);
|
||||
continente.setNombre(nombre);
|
||||
|
||||
continenteDAO.crearContinente(continente);
|
||||
|
||||
System.out.println("Continente creado correctamente.");
|
||||
}
|
||||
|
||||
private void buscarPorCodigo() {
|
||||
|
||||
System.out.print("Introduce el código: ");
|
||||
String codigo = scanner.nextLine();
|
||||
|
||||
Continente continente = continenteDAO.obtenerContinentePorClave(codigo);
|
||||
|
||||
if (continente != null) {
|
||||
System.out.println("Código: " + continente.getCodigo());
|
||||
System.out.println("Nombre: " + continente.getNombre());
|
||||
} else {
|
||||
System.out.println("No se encontró el continente.");
|
||||
}
|
||||
}
|
||||
|
||||
private void buscarPorNombre() {
|
||||
|
||||
System.out.print("Introduce el nombre: ");
|
||||
String nombre = scanner.nextLine();
|
||||
|
||||
List<Continente> lista = continenteDAO.obtenerContinentePorNombre(nombre);
|
||||
|
||||
for (Continente c : lista) {
|
||||
System.out.println(c.getCodigo() + " - " + c.getNombre());
|
||||
}
|
||||
}
|
||||
|
||||
private void listarContinentes() {
|
||||
|
||||
List<Continente> lista = continenteDAO.obtenerListaContinentes();
|
||||
|
||||
for (Continente c : lista) {
|
||||
System.out.println(c.getCodigo() + " - " + c.getNombre());
|
||||
}
|
||||
}
|
||||
|
||||
private void actualizarContinente() {
|
||||
|
||||
System.out.print("Código del continente a actualizar: ");
|
||||
String codigo = scanner.nextLine();
|
||||
|
||||
System.out.print("Nuevo nombre: ");
|
||||
String nombre = scanner.nextLine();
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigo);
|
||||
continente.setNombre(nombre);
|
||||
|
||||
continenteDAO.actualizarContinente(continente);
|
||||
|
||||
System.out.println("Continente actualizado.");
|
||||
}
|
||||
|
||||
private void borrarContinente() {
|
||||
|
||||
System.out.print("Código del continente a borrar: ");
|
||||
String codigo = scanner.nextLine();
|
||||
|
||||
Continente continente = new Continente();
|
||||
continente.setCodigo(codigo);
|
||||
|
||||
continenteDAO.borrarContinente(continente);
|
||||
|
||||
System.out.println("Continente eliminado.");
|
||||
}
|
||||
}
|
||||
14
src/main/java/org/lapaloma/mapamundi/dao/IContinenteDAO.java
Normal file
14
src/main/java/org/lapaloma/mapamundi/dao/IContinenteDAO.java
Normal file
@ -0,0 +1,14 @@
|
||||
package org.lapaloma.mapamundi.dao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.mapamundi.vo.Continente;
|
||||
|
||||
public interface IContinenteDAO {
|
||||
public Continente obtenerContinentePorClave(String codigo) ;
|
||||
public Continente actualizarContinente(Continente coche) ;
|
||||
public Continente crearContinente(Continente coche);
|
||||
public void borrarContinente(Continente coche);
|
||||
public List<Continente> obtenerListaContinentes();
|
||||
public List<Continente> obtenerContinentePorNombre(String nombre);
|
||||
}
|
||||
@ -0,0 +1,181 @@
|
||||
package org.lapaloma.mapamundi.dao.impl;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lapaloma.mapamundi.dao.IContinenteDAO;
|
||||
import org.lapaloma.mapamundi.gestores.GestorConexionJDBC;
|
||||
import org.lapaloma.mapamundi.vo.Continente;
|
||||
|
||||
public class ContinenteDaoJDBC implements IContinenteDAO {
|
||||
|
||||
@Override
|
||||
public Continente obtenerContinentePorClave(String codigo) {
|
||||
Continente continente = null;
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, codigo);
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
if (resultadoSentencia.next()) {
|
||||
continente = getLineaFromResultSet(resultadoSentencia);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Continente actualizarContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
UPDATE T_CONTINENTE
|
||||
SET nombre_continente=?
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getNombre());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getCodigo());
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Continente crearContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
INSERT INTO T_CONTINENTE (codigo, nombre_continente)
|
||||
VALUES (?, ?)
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
sentenciaJDBCPreparada.setString(2, continente.getNombre());
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return continente;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void borrarContinente(Continente continente) {
|
||||
|
||||
String sentenciaSQL = """
|
||||
DELETE FROM T_CONTINENTE
|
||||
WHERE codigo=?
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, continente.getCodigo());
|
||||
|
||||
sentenciaJDBCPreparada.executeUpdate();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerListaContinentes() {
|
||||
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
while (resultadoSentencia.next()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Continente> obtenerContinentePorNombre(String nombre) {
|
||||
|
||||
List<Continente> lista = new ArrayList<>();
|
||||
|
||||
String sentenciaSQL = """
|
||||
SELECT * FROM T_CONTINENTE
|
||||
WHERE nombre_continente LIKE ?
|
||||
""";
|
||||
|
||||
try (Connection conexion = GestorConexionJDBC.getConexionSGDB();
|
||||
PreparedStatement sentenciaJDBCPreparada = conexion.prepareStatement(sentenciaSQL);) {
|
||||
|
||||
sentenciaJDBCPreparada.setString(1, "%" + nombre + "%");
|
||||
|
||||
System.out.println(sentenciaJDBCPreparada);
|
||||
|
||||
ResultSet resultadoSentencia = sentenciaJDBCPreparada.executeQuery();
|
||||
|
||||
while (resultadoSentencia.next()) {
|
||||
lista.add(getLineaFromResultSet(resultadoSentencia));
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return lista;
|
||||
}
|
||||
|
||||
private Continente getLineaFromResultSet(ResultSet resultadoSentencia) throws SQLException {
|
||||
|
||||
Continente continente = new Continente();
|
||||
|
||||
continente.setCodigo(resultadoSentencia.getString("codigo"));
|
||||
continente.setNombre(resultadoSentencia.getString("nombre_continente"));
|
||||
|
||||
return continente;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package org.lapaloma.mapamundi.gestores;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
|
||||
public class GestorConexionJDBC {
|
||||
|
||||
// Evita que pueda construirse un objeto de la clase.
|
||||
private GestorConexionJDBC() {
|
||||
}
|
||||
|
||||
public static Connection getConexionSGDB() throws Exception {
|
||||
Connection conexionSGDB = null;
|
||||
|
||||
// Datos URL
|
||||
String urlBBDD = GestorFicheroConfiguracion.obtenerValor("jdbc.url");
|
||||
|
||||
String usuario = GestorFicheroConfiguracion.obtenerValor("jdbc.usuario");
|
||||
String contrasenya = GestorFicheroConfiguracion.obtenerValor("jdbc.password");
|
||||
|
||||
String claseDriver = GestorFicheroConfiguracion.obtenerValor("jdbc.driver");
|
||||
Class.forName(claseDriver);
|
||||
|
||||
conexionSGDB = DriverManager.getConnection(urlBBDD, usuario, contrasenya);
|
||||
|
||||
return conexionSGDB;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.lapaloma.mapamundi.gestores;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 20 feb 2026
|
||||
*
|
||||
*/
|
||||
public class GestorFicheroConfiguracion {
|
||||
private static final Properties PROPIEDADES = new Properties();
|
||||
|
||||
static {
|
||||
try (InputStream is = GestorFicheroConfiguracion.class.getClassLoader()
|
||||
.getResourceAsStream("config.properties")) {
|
||||
if (is != null) {
|
||||
PROPIEDADES.load(is);
|
||||
} else {
|
||||
throw new IllegalStateException("No se encontró application.properties en el classpath");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Error al cargar application.properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene el valor asociado a la clave especificada.
|
||||
*
|
||||
* @param clave la clave a buscar
|
||||
* @return el valor o {@code null} si no existe
|
||||
*/
|
||||
public static String obtenerValor(String clave) {
|
||||
return PROPIEDADES.getProperty(clave);
|
||||
}
|
||||
}
|
||||
44
src/main/java/org/lapaloma/mapamundi/vo/Continente.java
Normal file
44
src/main/java/org/lapaloma/mapamundi/vo/Continente.java
Normal file
@ -0,0 +1,44 @@
|
||||
package org.lapaloma.mapamundi.vo;
|
||||
|
||||
/**
|
||||
*
|
||||
* Coche: Clase de persistencia que representa un coche de un concesionario.
|
||||
*
|
||||
* @author Isidoro Nevares Martín - IES Virgen de la Paloma
|
||||
* @date 03 marzo 2026
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class Continente {
|
||||
private String codigo;
|
||||
private String nombre;
|
||||
|
||||
public Continente(String codigo, String nombre) {
|
||||
super();
|
||||
this.codigo = codigo;
|
||||
this.nombre = nombre;
|
||||
}
|
||||
|
||||
public Continente() {
|
||||
super();
|
||||
}
|
||||
|
||||
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 "Coche [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
6
src/main/resources/config.properties
Normal file
6
src/main/resources/config.properties
Normal file
@ -0,0 +1,6 @@
|
||||
# Parámetros de conexión a la base de datos MapaMundi en SGDB MySQL
|
||||
jdbc.driver = com.mysql.cj.jdbc.Driver
|
||||
jdbc.url = jdbc:mysql://23.21.171.246:3306/mapa_mundi
|
||||
jdbc.usuario = isidoronm
|
||||
jdbc.password = 1234
|
||||
|
||||
Loading…
Reference in New Issue
Block a user