Proyecto Actividad 1.2
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
.settings/
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package org.palomafp.aadd.aqv;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.aqv.vo.Continente;
|
||||||
|
import org.palomafp.aadd.aqv.vo.Pais;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Fichero_02 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
imprimirInformacionPaises();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void imprimirInformacionPaises() {
|
||||||
|
String rutaFichero = "C:\\Users\\aadd\\fic02\\informacion_paises.txt";
|
||||||
|
File fichero = new File(rutaFichero);
|
||||||
|
|
||||||
|
if (!fichero.exists()) {
|
||||||
|
System.out.println("El fichero no se encuentra en la ruta: " + rutaFichero);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||||
|
String linea;
|
||||||
|
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
if (linea.startsWith("#") || linea.startsWith("--") || linea.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lineaLimpia = linea.replace("\"", "");
|
||||||
|
String[] datos = lineaLimpia.split(",");
|
||||||
|
|
||||||
|
if (datos.length == 4) {
|
||||||
|
String codContinente = datos[0].trim();
|
||||||
|
int identificador = Integer.parseInt(datos[1].trim());
|
||||||
|
String nombrePais = datos[2].trim();
|
||||||
|
String capital = datos[3].trim();
|
||||||
|
|
||||||
|
Continente continente = new Continente(codContinente, null);
|
||||||
|
Pais pais = new Pais();
|
||||||
|
pais.setIdentificador(identificador);
|
||||||
|
pais.setNombre(nombrePais);
|
||||||
|
pais.setCapital(capital);
|
||||||
|
pais.setContinente(continente);
|
||||||
|
|
||||||
|
System.out.println(pais.toString());
|
||||||
|
|
||||||
|
System.out.printf(
|
||||||
|
"INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (%d, '%s', '%s', '%s');%n",
|
||||||
|
pais.getIdentificador(), pais.getContinente().getCodigo(), pais.getCapital(),
|
||||||
|
pais.getNombre());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error de lectura/escritura: " + e.getMessage());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.err.println("Error de formato numérico: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package org.palomafp.aadd.aqv.vo;
|
||||||
|
|
||||||
|
public class Continente {
|
||||||
|
private String codigo;
|
||||||
|
private String nombre;
|
||||||
|
|
||||||
|
public Continente() {}
|
||||||
|
|
||||||
|
public Continente(String codigo, String nombre) {
|
||||||
|
this.codigo = codigo;
|
||||||
|
this.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Continente [codigo=" + codigo + ", nombre=" + nombre + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package org.palomafp.aadd.aqv.vo;
|
||||||
|
|
||||||
|
public class Pais {
|
||||||
|
private int identificador;
|
||||||
|
private String nombre;
|
||||||
|
private String capital;
|
||||||
|
private Continente continente;
|
||||||
|
|
||||||
|
public Pais() {}
|
||||||
|
|
||||||
|
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 + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user