Click here to Skip to main content
15,903,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When you click the button, even if the Employee does not exist, MessageBox is shown that the Data has been deleted.
Java
if(evt.getSource()==btnDelete){
            try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection con = DriverManager.getConnection("jdbc:odbc:table1");
            Statement st = con.createStatement();
            int empno = Integer.parseInt(txtDelete.getText());
            
            ResultSet rs = st.executeQuery("SELECT * FROM Activity where employee_number='"+empno+"'");
                int i = st.executeUpdate("DELETE FROM Activity where employee_number ='"+empno+"'");
            
                while(rs.next()){
                    ResultSet.getInt(empno);
           
            JOptionPane.showMessageDialog(null, "Row is deleted");
            txtDelete.setText("");
             txtAdd1.setText("");
            txtAdd2.setText("");
            txtAdd3.setText("");
            txtAdd4.setText("");
            con.close();
            st.close();
                }
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Data not found");
        }
        }
    }
Posted
Updated 10-Dec-13 14:48pm
v2
Comments
baliram bhande 11-Dec-13 2:37am    
what error they give?

1 solution

You are already retrieving an answer for your command to the DB:

Java
int i = st.executeUpdate("DELETE FROM Activity where employee_number ='"+empno+"'");


The return value is the number of rows affected by the command. As you are deleting it should return -1 if successful:

Java
if(i == -1){
 // celebrate! 
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900