0

I am trying to solve this issue since 2 days but I am not able to solve it. Basically I am want that if the result of pst = conn.prepareStatement("select * from employee where cnic = ?"); is returning empty set than if(rs.next()) will execute and if it returning some data than program skip if and execute else part. I don't know where I am getting NullPointerException. I think I am getting exception after the execution of pst = conn.prepareStatement("select * from employee where cnic = ?"); I don't how to solve it so please help me

try {
                while(!bool){
                    pst = conn.prepareStatement("select * from employee where cnic = ?");
                    pst.setString(1, s9);
                    rs = pst.executeQuery();
                    if(rs.next()){
                        pst = conn.prepareStatement("insert into employee(id,firstname,lastname,age,gender,job,salary,phone,cnic,email) values(?,?,?,?,?,?,?,?,?,?)");
                        pst.setString(1, s1);
                        pst.setString(2, s2);
                        pst.setString(3, s3);
                        pst.setString(4, s4);
                        pst.setString(5, s5);
                        pst.setString(6, s6);
                        pst.setString(7, s7);
                        pst.setString(8, s8);
                        pst.setString(9, s9);
                        pst.setString(10, s10);
                        JOptionPane.showMessageDialog(null, "Employee Added Successfully");
                        new EmployeeMenu().setVisible(true);
                        setVisible(false);
                        bool = true;
                    }else {
                        JOptionPane.showMessageDialog(null, "This CNIC Number is Already Registered");
                        s9 = JOptionPane.showInputDialog("Enter a correct CNIC Number:");                           
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(AddEmployee.class.getName()).log(Level.SEVERE, null, ex);
            }

0 Answers0