Subida Actividad 1.2
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 + "]";
|
||||
}
|
||||
}
|
||||
@@ -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 + "]";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user