Guest User

Untitled

a guest
Dec 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. public Producto(String strNombreProd, double fltPrecio, double fltPrecioMayor, int intCantidad, String strUbicacion) {
  2. this.strNombreProd = strNombreProd;
  3. this.fltPrecio = fltPrecio;
  4. this.fltPrecioMayor = fltPrecioMayor;
  5. this.intCantidad = intCantidad;
  6. this.strUbicacion = strUbicacion;
  7. }
  8.  
  9. private void btnActualizaNombreMouseClicked(java.awt.event.MouseEvent evt) {
  10. try {
  11. String nombre = JOptionPane.showInputDialog(null, "Ingrese el nuevo nombre de:n" + txtNombre.getText());
  12. txtNombre.setText(nombre);
  13. producto = new Producto(txtNombre.getText(), Double.parseDouble(txtPrecio.getText()), Double.parseDouble(txtPrecioM.getText()), Integer.parseInt(txtCantidad.getText()), txtUbicacion.getText());
  14. material.UpdateProducto(producto);
  15. updateTabla();
  16. } catch (NullPointerException | NumberFormatException e) {
  17. e.printStackTrace();
  18. }
  19. }
  20.  
  21. public void UpdateProducto(Producto producto){
  22. try {
  23. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empresa", "root", "pass");
  24. String Sentencia = "UPDATE producto SET Nombre_Producto = ?,Precio = ?, Precio_Mayor = ?, Cantidad = ?, Ubicacion = ? WHERE Nombre_Producto = ?";
  25. ps = con.prepareStatement(Sentencia);
  26. ps.setString(1, producto.getStrNombreProd());
  27. ps.setDouble(2, producto.getFltPrecio());
  28. ps.setDouble(3, producto.getFltPrecioMayor());
  29. ps.setInt(4, producto.getIntCantidad());
  30. ps.setString(5, producto.getStrUbicacion());
  31. ps.setString(6, producto.getStrNombreProd());
  32. ps.executeUpdate();
  33. } catch (SQLException ex) {
  34. ex.printStackTrace();
  35. } finally {
  36. try {
  37. ps.close();
  38. con.close();
  39. } catch (SQLException ex) {
  40. Logger.getLogger(DATMaterial.class.getName()).log(Level.SEVERE, null, ex);
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment