Error al insertar datos ala base de datos desde netbeans
Publicado por Carlos (4 intervenciones) el 07/07/2020 19:59:37
Me sale este error al momento de guardar en la base de datos los datos de un usuario...espero su ayuda pronto...
jul 07, 2020 12:55:32 PM Formularios.frmPrincipal btnGuardarActionPerformed
GRAVE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'td,documento,nombre,apellido,telefono,fecha_ing,hora_ing,motivo VALUES ('TI',...' at line 1
---------------------------------------------------------------------------------------------------------------------------------------------------------
Este es el codigo dentro del boton guardar:
-------------------------------------------------------------------------------------------------------------------------------------------------------
Este es el codigo de la clase ConexioBD:
jul 07, 2020 12:55:32 PM Formularios.frmPrincipal btnGuardarActionPerformed
GRAVE: null
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'td,documento,nombre,apellido,telefono,fecha_ing,hora_ing,motivo VALUES ('TI',...' at line 1
---------------------------------------------------------------------------------------------------------------------------------------------------------
Este es el codigo dentro del boton guardar:
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
ConexionBD Con = new ConexionBD();
Con.ConectarBD();
String td = cbTD.getSelectedItem().toString();
String doc = txtDocumento.getText();
String nom = txtNombre.getText();
String ape = txtApellido.getText();
String tel = txtTelefono.getText();
String dir = txtDireccion.getText();
String fi = txtFechaI.getText();
String hi = txtHoraI.getText();
String mot = txtMotivo.getText();
if (!td.isEmpty()) {
if (!doc.isEmpty()) {
if (!nom.isEmpty()) {
if (!ape.isEmpty()) {
if (!tel.isEmpty()) {
if (!dir.isEmpty()) {
if (!fi.isEmpty()) {
if (!hi.isEmpty()) {
if (!mot.isEmpty()) {
try {
String SQL = "INSERT INTO personas "
+ "td,documento,nombre,apellido,telefono,fecha_ing,hora_ing,motivo"
+ " VALUES "
+ "('"+td+"','"+doc+"','"+nom+"','"+ape+"','"+tel+"','"+dir+"','"+fi+"','"+hi+"','"+mot+"',);";
Con.sentencia.execute(SQL);
JOptionPane.showMessageDialog(null, "¡Los datos fueron guardados con exito!");
} catch (SQLException ex) {
Logger.getLogger(frmPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
JOptionPane.showMessageDialog(null, "Por favor digite el motivo de ingreso");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor digite la hora de ingreso");
}
}else {
JOptionPane.showMessageDialog(null, "Por favor digite la fecha de ingreso");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor ingrese una direccion");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor ingrese su numero de telefonico");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor ingrese su apellido");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor ingrese su nombre");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor ingrese su documento ");
}
} else {
JOptionPane.showMessageDialog(null, "Por favor escoja una opcion TI, CC, RC, CE");
}
-------------------------------------------------------------------------------------------------------------------------------------------------------
Este es el codigo de la clase ConexioBD:
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
36
public class ConexionBD {
public Connection conexion;
public Statement sentencia;
public ResultSet resultado;
public void ConectarBD() {
try {
final String Controlador = "com.mysql.jdbc.Driver";
Class.forName(Controlador);
final String url_bd = "jdbc:mysql://localhost:3306/registro2";
conexion = DriverManager.getConnection(url_bd, "root", "root");
sentencia = conexion.createStatement();
} catch (ClassNotFoundException | SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
public void DesconectarBD() {
try {
if (conexion != null) {
if (sentencia != null){
sentencia.close();
}
conexion.close();
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
public Connection getConnection() {
return conexion;
}
}
Valora esta pregunta


0