Advertisement
Guest User

Untitled

a guest
Jan 1st, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. private void btn_ingresarMouseClicked(java.awt.event.MouseEvent evt) {
  2. Insumo obj= new Insumo();
  3. obj.setUsuario(txtrut.getText());
  4. obj.setPass(jPasswordField1.getText());
  5. try {
  6. obj.insertar();
  7. }
  8. catch(SQLException e){
  9. System.out.println(e.getMessage());
  10. }
  11.  
  12.  
  13. }
  14.  
  15. public class Conexion {
  16. public static Connection con = null;
  17.  
  18. public Connection Conectarse(){
  19. try {
  20. Class.forName("com.mysql.jdbc.Driver").newInstance();
  21. System.out.println("Registro exitoso");
  22. Connection con = DriverManager.getConnection(
  23. "jdbc:mysql://localhost:3306/ropa_trabajo?"
  24. + "user=root&password=");
  25. } catch (Exception e) {
  26.  
  27. System.out.println(e.toString()+"dsgdsh");
  28.  
  29. }
  30. return con;
  31. }
  32.  
  33. public void cerrar() throws SQLException {
  34. if(con!=null){
  35. con.close();
  36. }
  37. }
  38. }
  39.  
  40. public class Insumo extends Conexion {
  41. private String usuario;
  42. private String pass;
  43.  
  44.  
  45. public Insumo(){
  46. super();
  47. con=super.Conectarse();
  48. }
  49.  
  50.  
  51.  
  52.  
  53. public void insertar() throws SQLException{
  54. String sql="INSERT INTO usuario(4,?,?)";
  55. PreparedStatement sentencia=super.Conectarse().prepareStatement(sql);
  56. sentencia.setString(1,getUsuario());
  57. sentencia.setString(2,getPass());
  58. sentencia.executeUpdate();
  59. super.cerrar();
  60.  
  61. }
  62.  
  63. /**
  64. * @return the usuario
  65. */
  66. public String getUsuario() {
  67. return usuario;
  68. }
  69.  
  70. /**
  71. * @param usuario the usuario to set
  72. */
  73. public void setUsuario(String usuario) {
  74. this.usuario = usuario;
  75. }
  76.  
  77. /**
  78. * @return the pass
  79. */
  80. public String getPass() {
  81. return pass;
  82. }
  83.  
  84. /**
  85. * @param pass the pass to set
  86. */
  87. public void setPass(String pass) {
  88. this.pass = pass;
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement