多数の行が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;
}