
guardar datos en mysql
Publicado por Jose Augusto (3 intervenciones) el 30/03/2018 17:03:27
cual es el error porque no se guardan los datos en la base de datos :( dice que se conecto y todo pero cuando voy a guardar el formulario no se guarda en la base de datos
y el boton guardar
conexion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package VENTANAS;
import java.sql.*;
public class ConexionBD {
Connection cn;
public Connection conexion(){
try{
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection("jdbc:mysql://localhost/policia","root","12345");
System.out.println("Conexion Exitosa Oficial");
}catch(Exception e){
System.out.println(e.getMessage());
}return cn;
}
Statement createStatement(){
throw new UnsupportedOperationException("NO SOPORTADO");
}
}
y el 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
try {
PreparedStatement pst = cn.prepareStatement("INSERT INTO reseñas (Nombres y Apellidos,Fecha de Nacimiento,Edad,Cedula de Identidad,Estado Civil,Alias,Profecion u Oficio,Direccion de Habitacion,Direccion del Trabajo,Telefonos,Motivo,Prontuario Policial,Expediente,Delito) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,)");
pst.setString(1, txtnombre.getText());
pst.setString(2, txtfecha.getText());
pst.setString(3, txtedad.getText());
pst.setString(4, txtcedula.getText());
pst.setString(5, txtestado.getText());
pst.setString(6, txtalias.getText());
pst.setString(7, txtprofecion.getText());
pst.setString(8, txtdireccion.getText());
pst.setString(9, txtdireccion2.getText());
pst.setString(10, txttelefonos.getText());
pst.setString(11, txtmotivo.getText());
pst.setString(12, txtprontuario.getText());
pst.setString(13, txtexpediente.getText());
pst.setString(14, txtdelito.getText());
pst.executeUpdate();
} catch (Exception e) {
}
}
}
conexion
1
2
ConexionBD cc = new ConexionBD();
Connection cn= cc.conexion();
Valora esta pregunta


0