Cargar datos de un archivo .txt y Guardar datos de BD de mysql
Publicado por Devastador (15 intervenciones) el 01/11/2020 00:51:30
Cuando intento obtener datos de mi archivo .txt que tiene como separador "|" en la primera columna por asi decirlo no me tira error pero cuando pasa a la siguiente me tira error java.lang.NumberFormalException : For input string "|"
Ahora en el botón para cargar datos de un tabla de MySQL me no me da ningún error pero solo obtiene los datos de la primera fila y las otras 2 guardadas no
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
private void cargartxtActionPerformed(java.awt.event.ActionEvent evt) {
FileReader r;
try{
r = new FileReader("C:\\UMG\\Programacion\\Reporte_Incripción.txt");
BufferedReader buff = new BufferedReader(r);
String linea;
for (int i=0; i <array.length; i++){
linea = buff.readLine();
String [] valores = linea.split("|");
int num = Integer.parseInt(valores[0]);
String nom = valores[1];
String ape = valores[2];
String carn = valores[3];
String sex = valores[4];
int age = Integer.parseInt(valores[5]);
String cor = valores[6];
String facu1 = valores[7];
String talla1 = valores[8];
String txt = valores[9];
String mod1 = valores [10];
Float time = Float.parseFloat(valores[11]);
array[i] = new inscritos (num,nom,ape,carn,sex,age,cor,facu1,talla1,txt,mod1,time);
}
}
catch(Exception e){
JOptionPane.showMessageDialog(rootPane, "Error "+e,"Alerta",JOptionPane.ERROR_MESSAGE);
return;
}
}
Ahora en el botón para cargar datos de un tabla de MySQL me no me da ningún error pero solo obtiene los datos de la primera fila y las otras 2 guardadas no
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
private void cargarbasededatosActionPerformed(java.awt.event.ActionEvent evt) {
BD g2 = new BD();
Connection getter;
getter = g2.getConnection();
try{
ps2 = getter.prepareStatement("SELECT numcorredor,nombre,apellido,carnet,sexo,edad,correo,facultad,talla,textoplayera,modalidad,tiempocorr FROM inscritos");
ResultSet rs2 = ps2.executeQuery();
for (int i=0; i <array.length; i++){
while (rs2.next()){
int num = Integer.parseInt(rs2.getString("numcorredor"));
String nom = rs2.getString("nombre");
String ape = rs2.getString("apellido");
String carn = rs2.getString("carnet");
String sex = rs2.getString("sexo");
int age = Integer.parseInt(rs2.getString("edad"));
String cor = rs2.getString("correo");
String facu1 = rs2.getString("facultad");
String talla1 = rs2.getString("talla");
String txt = rs2.getString("textoplayera");
String mod1 = rs2.getString("modalidad");
Float time = Float.parseFloat(rs2.getString("tiempocorr"));
array[i] = new inscritos (num,nom,ape,carn,sex,age,cor,facu1,talla1,txt,mod1,time);
}
}
}catch (NumberFormatException | SQLException e) {
JOptionPane.showMessageDialog(rootPane, "Error al Cargar Base Datos"+e,"Alerta",JOptionPane.ERROR_MESSAGE);
}
}
Valora esta pregunta


0