我有这两种方法:
public void Delete(){
try{
PreparedStatement stmt = activeConn.prepareStatement("DELETE FROM lid WHERE lid_id = ?");
int selectedID = (int) table.getModel().getValueAt(table.getSelectedRow(), 0);
stmt.setInt(1, selectedID);
stmt.executeUpdate();
stmt.close();
}
catch(SQLException e){
System.out.println(e);
}
}
和
public int getID(){
int id = (int) table.getModel().getValueAt(table.getSelectedRow(), 0);
return id;
}
第一个应该删除 mysql 表中的某一行。它工作完美。第二个应该只给出第一列所选行的值(即表中的 id)。但它给了我“”AWT-EventQueue-0”java.lang.ArrayIndexOutOfBoundsException:-1”错误。
最佳答案
我认为,您需要调用:
javax.swing.table.AbstractTableModel.fireTableDataChanged()
从数据库中删除一行后。
关于Java table.getmode.getvalueat(row, column) 在 1 种方法中工作,而不在其他方法中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37603631/