first commmit
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
/bin/
|
||||||
|
*.class
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
Binary file not shown.
@@ -0,0 +1,68 @@
|
|||||||
|
package org.palomafp.aadd.rmr;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.palomafp.aadd.rmr.vo.Continente;
|
||||||
|
import org.palomafp.aadd.rmr.vo.Pais;
|
||||||
|
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
// este método se ejecuta al arrancar el programa
|
||||||
|
public static void main (String[] args) {
|
||||||
|
|
||||||
|
// llamo al método que va a procesar mi fichero
|
||||||
|
imprimirInformacionPaises();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void imprimirInformacionPaises() {
|
||||||
|
// el codiguito va aquí
|
||||||
|
try {
|
||||||
|
|
||||||
|
// preparo para leer el archivo de la ruta
|
||||||
|
BufferedReader br = new BufferedReader (new FileReader("C:/Users/Rocío/aadd/fic02/informacion_paises.txt"));
|
||||||
|
String linea = ""; // guardo cada línea aquí
|
||||||
|
|
||||||
|
// bucle donde leo línea a línea hasta que no haya más
|
||||||
|
while ((linea = br.readLine()) != null) {
|
||||||
|
|
||||||
|
// si la lóinea mepieza por # o - la ignoro y no hace nada
|
||||||
|
if (linea.startsWith("#") || linea.startsWith("-")) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// paso 1. limpio los datos
|
||||||
|
linea = linea.replace("\"", ""); // quito todas las comillas dobles
|
||||||
|
String[] trozos = linea.split(","); // parto la línea por las comas para tener lso 4 datos
|
||||||
|
|
||||||
|
// paso 2. meto los datos en objetos
|
||||||
|
Continente c = new Continente(); // creo el continente
|
||||||
|
c.setCodigo(trozos[0].trim()); // guardo el code quitándole los espacios
|
||||||
|
|
||||||
|
Pais p = new Pais();
|
||||||
|
p.setIdentificador(Integer.parseInt(trozos[1].trim())); // convierto a num el identificador
|
||||||
|
p.setNombre(trozos[2].trim()); // meto el nombre
|
||||||
|
p.setCapital(trozos[3].trim()); // meto la capital
|
||||||
|
p.setContinente(c); // mteo el objeto continente dentro de país
|
||||||
|
|
||||||
|
// paso 3. imprimo l oque se ipde
|
||||||
|
System.out.println(p.toString());
|
||||||
|
|
||||||
|
// paso 4. monto la frase sql sacando los datos de los objetos que he creado arriba
|
||||||
|
System.out.println("INSERT INTO T_PAIS (cod_continente, identificador, capital, nombre_pais) VALUES (" + p.getIdentificador() + ", '" + c.getCodigo() + "', '" + p.getCapital() + "', '" + p.getNombre() + "');");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.println("El archivo no se encuentra.");
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println("Ha ocurrido un error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.palomafp.aadd.rmr.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,49 @@
|
|||||||
|
package org.palomafp.aadd.rmr.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