Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rellnabd;
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.InputStreamReader;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- /**
- *
- * @author keko
- */
- public class RellnaBd {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- String contenido = "F://colo.txt";
- try
- {
- //ruta puede ser de tipo String o tipo File
- String ruta = "F://CapturaDeVoto.txt";
- FileReader fr = new FileReader( ruta );
- BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(ruta), "ISO-8859-1") );
- String linea;
- //Obtenemos el contenido del archivo linea por linea
- while( ( linea = br.readLine() ) != null ){
- //System.out.println(linea);
- String diaArray[] = linea.split(",");
- int Afected;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sistemamonitoreo","root", "1234"); // OJO esta linea depende de tu base de datos, el 1234 es la contrasenia
- Statement stat = con.createStatement();
- String SQL = "INSERT INTO aspiranteresponsable (Nombre,) VALUES ('" + diaArray[0] + "','" + diaArray[2] + "','" + diaArray[1] + "','" + diaArray[4] + "')";
- System.out.println(" "+diaArray[0]+ " "+ diaArray[1]+ " " + diaArray[2] + " " + diaArray[3]+ " " + diaArray[4]);
- System.out.println(SQL);
- PreparedStatement preparedStmt = con.prepareStatement(SQL,new String[]{"idcolonias"});
- //preparedStmt.executeUpdate();
- ResultSet rs = preparedStmt.getGeneratedKeys();
- if (rs.next()) {
- Afected = rs.getInt(1);
- // System.out.println(Afected);
- }
- }catch ( ClassNotFoundException | SQLException e ){
- System.out.println("Error: " + e.getMessage());
- }
- }
- }catch( Exception e ){
- System.out.println("No se pudo abrir: " + e);
- }
- //finally se utiliza para que si todo ocurre correctamente o si ocurre
- //algun error se cierre el archivo que anteriormente abrimos
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement