0

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

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by oggiemc
1

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.