I created two classes a connection for the BD and another Insumo
that will have an insert method. I execute the code but nothing happens. I think it's class Conexion
I'm not sure you could look at the code to see what the problem is
Click of the button
private void btn_ingresarMouseClicked(java.awt.event.MouseEvent evt){
Insumo obj= new Insumo();
obj.setUsuario(txtrut.getText());
obj.setPass(jPasswordField1.getText());
try {
obj.insertar();
}
catch(SQLException e){
System.out.println(e.getMessage());
}
}
Class Conexion
public class Conexion {
public static Connection con = null;
public Connection Conectarse(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("Registro exitoso");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/ropa_trabajo?"
+ "user=root&password=");
} catch (Exception e) {
System.out.println(e.toString()+"dsgdsh");
}
return con;
}
public void cerrar() throws SQLException {
if(con!=null){
con.close();
}
}
}
Class Insumo
.
The input class I think is where the problem is
public class Insumo extends Conexion {
private String usuario;
private String pass;
public Insumo(){
super();
con=super.Conectarse();
}
public void insertar() throws SQLException{
String sql="INSERT INTO usuario(4,?,?)";
PreparedStatement sentencia=super.Conectarse().prepareStatement(sql);
sentencia.setString(1,getUsuario());
sentencia.setString(2,getPass());
sentencia.executeUpdate();
super.cerrar();
}
/**
* @return the usuario
*/
public String getUsuario() {
return usuario;
}
/**
* @param usuario the usuario to set
*/
public void setUsuario(String usuario) {
this.usuario = usuario;
}
/**
* @return the pass
*/
public String getPass() {
return pass;
}
/**
* @param pass the pass to set
*/
public void setPass(String pass) {
this.pass = pass;
}
}