Hi, I'm having a problem when updating a field in my database, it does not throw me any errors, it just does not update the field in the database.
I have the Product Class and a constructor that is as follows:
public Producto(String strNombreProd, double fltPrecio, double fltPrecioMayor, int intCantidad, String strUbicacion) {
this.strNombreProd = strNombreProd;
this.fltPrecio = fltPrecio;
this.fltPrecioMayor = fltPrecioMayor;
this.intCantidad = intCantidad;
this.strUbicacion = strUbicacion;
}
And in my interface I have an event that when I click on an icon I can change the name of that product:
private void btnActualizaNombreMouseClicked(java.awt.event.MouseEvent evt) {
try {
String nombre = JOptionPane.showInputDialog(null, "Ingrese el nuevo nombre de:\n" + txtNombre.getText());
txtNombre.setText(nombre);
producto = new Producto(txtNombre.getText(), Double.parseDouble(txtPrecio.getText()), Double.parseDouble(txtPrecioM.getText()), Integer.parseInt(txtCantidad.getText()), txtUbicacion.getText());
material.UpdateProducto(producto);
updateTabla();
} catch (NullPointerException | NumberFormatException e) {
e.printStackTrace();
}
}
And I forgot this is the method where I connect to the database:
public void UpdateProducto(Producto producto){
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/empresa", "root", "pass");
String Sentencia = "UPDATE producto SET Nombre_Producto = ?,Precio = ?, Precio_Mayor = ?, Cantidad = ?, Ubicacion = ? WHERE Nombre_Producto = ?";
ps = con.prepareStatement(Sentencia);
ps.setString(1, producto.getStrNombreProd());
ps.setDouble(2, producto.getFltPrecio());
ps.setDouble(3, producto.getFltPrecioMayor());
ps.setInt(4, producto.getIntCantidad());
ps.setString(5, producto.getStrUbicacion());
ps.setString(6, producto.getStrNombreProd());
ps.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
} finally {
try {
ps.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(DATMaterial.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
I only have the error when updating the name_product field but when I update other fields, it updates them without problems