Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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());
- }
- }
- 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();
- }
- }
- }
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement