Primer commit.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package org.palomafp.aadd.ss;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AppPrincipal {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String rutaFichero = "C:\\Users\\sajed\\Desktop\\AADD\\aadd\\fic01\\informacion_paises.txt";
|
||||
File fichero = new File(rutaFichero);
|
||||
|
||||
if (!fichero.exists()) {
|
||||
System.err.println("El fichero no existe en la ruta: " + rutaFichero);
|
||||
return;
|
||||
}
|
||||
|
||||
// Lectura del fichero utilizando BufferedReader y FileReader
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(fichero))) {
|
||||
String linea;
|
||||
|
||||
while ((linea = br.readLine()) != null) {
|
||||
// Si el fichero viene separado por comas o punto y coma:
|
||||
// Ejemplo de línea: 02; 65; Colombia; Bogotá
|
||||
String[] datos = linea.split(";"); // Cambia ';' por ',' si tu archivo usa comas
|
||||
// System.out.println(datos);
|
||||
if (datos.length >= 4) {
|
||||
String codigo = datos[0].trim();
|
||||
int prefijo = Integer.parseInt(datos[1].trim());
|
||||
String pais = datos[2].trim();
|
||||
String capital = datos[3].trim();
|
||||
|
||||
// Construcción del INSERT con el formato exacto del ejemplo:
|
||||
// INSERT INTO T_PAIS VALUES ('02',65, 'Colombia', 'Bogotá');
|
||||
String sql = String.format(
|
||||
"INSERT INTO T_PAIS VALUES ('%s', %d, '%s', '%s');",
|
||||
codigo, prefijo, pais, capital
|
||||
);
|
||||
|
||||
System.out.println(sql);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error al leer el archivo: " + e.getMessage());
|
||||
} catch (NumberFormatException e) {
|
||||
System.err.println("Error al formatear un número: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user