I can not get my Java application to delete data from a database.
I attach code to my method to erase:
int rowIndex = this.tabla.getSelectedRow();
try{
String dni = String.valueOf( tabla.getValueAt(rowIndex, 0));
st = con.createStatement();
int fila = tabla.getSelectedRow();
int col = tabla.getSelectedColumn();
System.out.println(fila);
System.out.println(col);
String sql = "DELETE FROM clientes where dni="+dni;
st.executeUpdate(sql);
modelo.removeRow(fila);
JOptionPane.showMessageDialog(null, "Datos Borrados");
}catch(SQLException e){
JOptionPane.showMessageDialog(null, "Error al borrar");
}
that code is called from a button in its actionListener . I've tried prepareStatement , and neither. I'm not interested in this form, since I do not know how to pass the DNI from a JTable as a parameter to the method.