Advertisement
Guest User

Untitled

a guest
Dec 30th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. private void btn_ingresarMouseClicked(java.awt.event.MouseEvent evt) {
  2. /* Insumo obj= new Insumo();
  3. obj.setDescripcion(txtrut.getText());
  4. JOptionPane.showMessageDialog(null, obj.getDescripcion());*/
  5. String name=txtrut.getText();
  6. String pass=jPasswordField1.getText();
  7. String sql="INSERT INTO usuario values(1,"+name+","+pass+")";
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver").newInstance();
  10. System.out.println("Registro exitoso");
  11.  
  12. } catch (Exception e) {
  13.  
  14. System.out.println(e.toString());
  15.  
  16. }
  17.  
  18. Connection con= null;
  19.  
  20. try {
  21.  
  22. con = DriverManager.getConnection(
  23. "jdbc:mysql://localhost:3306/ropa_trabajo?"
  24. + "user=root&password=");
  25.  
  26. // Otros y operaciones sobre la base de datos...
  27. Statement sentencia=con.createStatement();
  28. sentencia.executeUpdate(sql);
  29. con.close();
  30. } catch (SQLException ex) {
  31.  
  32. // Mantener el control sobre el tipo de error
  33. System.out.println("SQLException: " + ex.getMessage());
  34.  
  35. }
  36.  
  37. System.out.println(sql);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement