可以,我正在作个大作业,就有这个功能,代码为
private void delete(){
int[] selectedRows = table.getSelectedRows(); table是JTable的实例,这一句返回了所选的行标
if( selectedRows == null ) {
JOptionPane.showMessageDialog(null, "尚未选中项目");
return;
}
for(int i=0;i<selectedRows.length;i++){
String deleteNum = (String)table.getValueAt(selectedRows[i],0);
String deleteSQL = "delete * from student where 卡号=" + deleteNum;
String tempS = JOptionPane.showInputDialog(new JTextField(),"请输入管理员密码:");
if(tempS == null) return;
else if( tempS!="123456") {
JOptionPane.showMessageDialog(null,"密码错误!");
return;
}
try {
st.executeUpdate(deleteSQL);
}
catch (Exception ex) {
JOptionPane.showMessageDialog(null, "删除卡号"+deleteNum+"失败");
};
}
}