I will begin by saying that I googled the problem and found explanation but still can not fix the error...:s
I'm getting java.sql.SQLException: Operation not allowed after
ResultSetclosed
(what I understand is that I should create a new statement and new ResultSet
and like said still can't make it work - if that is now right way of thinking)
would appreciate all the help.
public class IdPanel extends JPanel {
private JLabel idLabel;
private JTextField idField;
private JButton okBtn;
private JButton newEmployeBtn;
private NewEmployeDialog newEmployeDialog;
private Connection myConn;
private Statement myStmt;
private ResultSet myRs;
public IdPanel() throws SQLException {
idLabel = new JLabel("ID:");
idField = new JTextField(12);
okBtn = new JButton("OK");
newEmployeBtn = new JButton("New Employe...");
myConn = DriverManager.getConnection(
"jdbc:mysql://*********", ********);
myStmt = myConn.createStatement();
myRs = myStmt.executeQuery("select * from employe");
try {
newEmployeDialog = new NewEmployeDialog();
} catch (SQLException e1) {
System.out.println("check IdPanel-->NewEmployeDialog");
}
setLayout(new GridBagLayout());
setGc();
okBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String id = idField.getText();
try {
while (myRs.next()) {
String idImp = myRs.getString(1);
if (id.equals(idImp)) {
System.out.println(id);
try {
myStmt.executeUpdate("update employe set phone =99321 where id=346");
} catch (SQLException e1) {
e1.printStackTrace();
}
}
idField.setText("");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
});
myConn.close();
myStmt.close();
myRs.close();
}