Hello people,

Im getting an
"Exception occured ---java.lang.NullPointerException"
error when i try running the code below:

public void Register(String Username, String Password,
                  String Surname, String Firstname, String Email, String Phone)
      {
              String a = Username;
              String b = Password;
              String c = Surname;
              String d = Firstname;
              String k = Email;
              String f = Phone;
            
            try
            {
            
            pstmt = con.prepareStatement("INSERT INTO FMC_EMPLOYEE " +
                        "(USERID,PASSWORD,SURNAME,FIRSTNAME,EMAIL,PHONE)VALUES(?,?,?,?,?,?)");

              pstmt.clearParameters();      
              pstmt.setString(1, a);
              pstmt.setString(2, b);
              pstmt.setString(3, c);
              pstmt.setString(4, d);
              pstmt.setString(5, k);
              pstmt.setString(6, f);
              pstmt.executeUpdate();
                  System.out.println("ID = " + a);
                                                                                                    
                                                                                                               
               stmt.close();

            }
            catch (Exception e) {
            System.out.println("Exception occured ---" + e);
      }
            
            
    }
}

I know the error is happening somewhere from "pstmt = con.prepareStatement("INSERT INTO FMC_EMPLOYEE " +" onwards, because the "System.out.println("ID = " + a);" is printing to the console..
Can someone tell me what im doing wrong here please?

PS The data is going into the database, im just concerned about this error.

Many Thanks

You are using something which is null. The error tells you the line where that happened. Also you are trying to close the 'stmt' variable but you are using the 'pstmt' to execute the query.

thanks java addict..its working now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.