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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user