我使用此代码获取我的身份证号码JTable
,
但"AWT-EventQueue-0" java.lang.ClassCastException
发生,
public void actionPerformed(ActionEvent e) {
if (e.getSource() == dellButton) {
try {
int rowToDelete = 0;
int rowToModel = 0;
if (table.getSelectedRow() > -1) {
rowToDelete = table.getSelectedRow();
rowToModel = table.convertRowIndexToModel(rowToDelete);
tableModel.removeRow(rowToModel);
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}
我的TableModel.removeRow()
方法:
...
public void removeRow(int rowNumber) throws SQLException {
String removeQuery = "delete from mytable where id=?";
PreparedStatement pStatement = con.prepareStatement(removeQuery);
pStatement.setInt(1, rowNumber);
int rowsAffected = pStatement.executeUpdate();
}
...