Hola buenas tardes, he tratado de buscar la solución del error pero no consigo encontrar es por ello que solicito de su ayuda, gracias
private void modificar() {
if (tieneFilaElegida()) {
JOptionPane.showMessageDialog(this, "Por favor, elije un item");
return;
}
Optional.ofNullable(modelo.getValueAt(tabla.getSelectedRow(), tabla.getSelectedColumn()))
.ifPresentOrElse(fila -> {
Integer id = Integer.valueOf(modelo.getValueAt(tabla.getSelectedRow(), 0).toString());
String nombre = (String) modelo.getValueAt(tabla.getSelectedRow(), 1);
String descripcion = (String) modelo.getValueAt(tabla.getSelectedRow(), 2);
Integer cantidad = Integer.valueOf(modelo.getValueAt(tabla.getSelectedRow(), 3).toString());
int filasModificadas;
try {
filasModificadas = this.productoController.modificar(nombre, descripcion, cantidad, id);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
JOptionPane.showMessageDialog(this, String.format("%d Item eliminado con éxito!", filasModificadas));
}, () -> JOptionPane.showMessageDialog(this, "Por favor, elije un item"));
}
public int modificar(String nombre, String descripcion, Integer cantidad, Integer id) throws SQLException {
ConnectionFactory factory = new ConnectionFactory();
Connection con = factory.recuperaConexion();
Statement statement = con.createStatement();
statement.execute("UPDATE producto SET "
+ " NOMBRE = '" + nombre + "'"
+ ", DESCRIPCION = '" + descripcion + "'"
+ ", CANTIDAD = " + cantidad
+ " WHERE ID = " + id );
int updateCount = statement.getUpdateCount();
con.close();
return updateCount;
}
el error que me marca es este
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 >= 3
at java.base/java.util.Vector.elementAt(Vector.java:497)
at java.desktop/javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:661)
at com.alura.jdbc.view.ControlDeStockFrame.lambda$0(ControlDeStockFrame.java:190)
at java.base/java.util.Optional.ifPresentOrElse(Optional.java:201)
at com.alura.jdbc.view.ControlDeStockFrame.modificar(ControlDeStockFrame.java:186)
at com.alura.jdbc.view.ControlDeStockFrame$4.actionPerformed(ControlDeStockFrame.java:154)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6635)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6400)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5011)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4843)