Guest User

Untitled

a guest
Oct 6th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. try {
  2.  
  3. Class.forName("com.mysql.jdbc.Driver");
  4. java.sql.Connection conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/tienda","root","");
  5.  
  6.  
  7. String nombre = textField_1.getText();
  8. int precio = Integer.parseInt(textField_2.getText());
  9. String descripcion = textArea.getText();
  10.  
  11. JTextField textField_3 = new JTextField();
  12. SimpleDateFormat form = new SimpleDateFormat("dd/MM/yyyy");
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. String query = "INSERT INTO productos (nombre,precio,descripcion) values('"+nombre+"','"+precio+"','"+descripcion+"')";
  21.  
  22. Statement s = conexion.createStatement();
  23. s.executeUpdate(query);
  24.  
  25. JOptionPane.showMessageDialog(null, "Nombre agregado");
  26.  
  27.  
  28. } catch (Exception e) {
  29.  
  30. JOptionPane.showMessageDialog(null, "Error");
  31. // TODO: handle exception
  32. }
  33.  
  34. }
  35. });
Add Comment
Please, Sign In to add comment