【发布时间】:2012-10-09 08:00:27
【问题描述】:
我在JTable 中有很多行,每行都有删除按钮。当我单击该行的删除按钮时,我想删除当前行。我该怎么做?
private JButton button;
public MyTableButtonEditor1() {
button = new JButton("REMOVE");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DbUtility ViewEmployee =new DbUtility();
ViewEmployee.loadDriver();
ViewEmployee.connect();
ResultSet rs= ViewEmployee.executeDeleteQuery(Employeeid);
JOptionPane.showMessageDialog(null, "Employee Removed");
}
});
}
数据库连接
public ResultSet executeDeleteQuery(String Employeeid ) {
PreparedStatement pstmt ;
try {
pstmt = conn.prepareStatement("DELETE FROM employee WHERE EmployeeId ="+Employeeid );
pstmt.execute();
}
catch (SQLException ex){
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
return rs;
}
【问题讨论】:
-
请学习 java 命名约定并遵守它们 - 它会更容易阅读:-)
-
首先:阅读教程中的示例(在 swing tag wiki 中引用),了解如何将按钮用作 cellEditor 第二:应用所学课程并再次提问(然后答案会更有意义给你)