From 965ed6935909204e76767d92c83ab93711a8401d Mon Sep 17 00:00:00 2001 From: "marcos.alcalde1" Date: Sat, 26 Sep 2026 14:18:39 +0200 Subject: [PATCH] Subida Actividad 1.2 --- AppPrincipal.java | 74 +++++++++++++++++++++++++++++++++++++++++++++++ Continente.java | 28 ++++++++++++++++++ Pais.java | 47 ++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 AppPrincipal.java create mode 100644 Continente.java create mode 100644 Pais.java diff --git a/AppPrincipal.java b/AppPrincipal.java new file mode 100644 index 0000000..cb88533 --- /dev/null +++ b/AppPrincipal.java @@ -0,0 +1,74 @@ +package org.palomafp.aadd.mag; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.palomafp.aadd.mag.vo.Continente; +import org.palomafp.aadd.mag.vo.Pais; + +public class AppPrincipal { + + private static final String RUTA_FICHERO = "C:\\Users\\alumnoT\\aadd\\fic02\\informacion_paises.txt"; + + public static void main(String[] args) { + AppPrincipal app = new AppPrincipal(); + app.imprimirInformacionPaises(); + } + + private void imprimirInformacionPaises() { + BufferedReader reader = null; + try { + File ficheroPaises = new File(RUTA_FICHERO); + reader = new BufferedReader(new FileReader(ficheroPaises)); + + String linea; + while ((linea = reader.readLine()) != null) { + linea = linea.trim(); + + if (!linea.startsWith("#") && !linea.startsWith("--") && !linea.isEmpty()) { + String[] camposPais = linea.split(","); + + if (camposPais.length >= 4) { + String codigoContinente = camposPais[0].trim().replace("\"", ""); + int idPais = Integer.parseInt(camposPais[1].trim()); + String nombrePais = camposPais[2].trim().replace("\"", ""); + String capitalPais = camposPais[3].trim().replace("\"", ""); + + Continente continente = new Continente(); + continente.setCodigo(codigoContinente); + + Pais pais = new Pais(); + pais.setIdentificador(idPais); + pais.setNombre(nombrePais); + pais.setCapital(capitalPais); + pais.setContinente(continente); + + System.out.println(pais); + + String sentenciaSQL = "INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (" + + pais.getIdentificador() + ", '" + + pais.getContinente().getCodigo() + "', '" + + pais.getCapital() + "', '" + + pais.getNombre() + "');"; + + System.out.println(sentenciaSQL); + } + } + } + + reader.close(); + + } catch (IOException e) { + System.out.println("Error al leer el archivo: " + e.getMessage()); + if (reader != null) { + try { + reader.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } +} \ No newline at end of file diff --git a/Continente.java b/Continente.java new file mode 100644 index 0000000..ceddd63 --- /dev/null +++ b/Continente.java @@ -0,0 +1,28 @@ +package org.palomafp.aadd.mag.vo; + +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 + "]"; + } +} \ No newline at end of file diff --git a/Pais.java b/Pais.java new file mode 100644 index 0000000..836b1c4 --- /dev/null +++ b/Pais.java @@ -0,0 +1,47 @@ +package org.palomafp.aadd.mag.vo; + +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 + "]"; + } +} \ No newline at end of file