#1
  1. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0

    Null pointer exception error


    <%
    String changesrno = request.getParameter("Changesrno");
    String changename = request.getParameter("Changename");
    String changefname = request.getParameter("Changefname");
    //change first name to uppercase
    String fnameU = changefname.substring(0,1).toUpperCase() + changefname.substring(1);
    String changelname = request.getParameter("Changelname");
    //change last name to uppercase
    String lnameU = changelname.substring(0,1).toUpperCase() + changelname.substring(1);
    String changeremarks = request.getParameter("Changeremarks");
    String changestatus = request.getParameter("Changestatus");
    //add space between fname and lname
    String changefullname = fnameU + " " +lnameU;
    //add space between fname and lname
    String AAname = fnameU + " " +lnameU;
    //add space between fname and lname
    String email = fnameU + " " +changelname;
    //replace space with underscore
    String emailreplace = email.replace(' ','_');
    //change email to lower case
    String emailL = emailreplace.toLowerCase()+"@moe.edu.sg";
    //check if user clicks on which button
    String check = request.getParameter("save");
    String check2 = request.getParameter("reset");

    Connection connection = null;
    Statement statement = null;
    ResultSet rs = null;
    ResultSet rs2 = null;
    ResultSet rs3 = null;

    String full_name;
    boolean checking=false;
    String email_Add;
    boolean checking2=false;

    //Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    connection = DriverManager.getConnection(connectionURL, "", "");
    statement = connection.createStatement();

    rs2 = statement.executeQuery("SELECT * from SR_MsgSvc_Creation");
    //check if full name exist
    while(rs2.next())
    {
    full_name = rs2.getString("Full_Name");
    if(changefullname.equalsIgnoreCase(full_name))
    {
    //if exist, set checking to true
    checking=true;
    break;
    }
    }

    rs3 = statement.executeQuery("SELECT Email_Address from SR_MsgSvc_Creation");
    //check if emailaddress exist
    while(rs3.next())
    {
    email_Add = rs3.getString(1);
    if(emailL.equalsIgnoreCase(email_Add))
    {
    //if exist, set checking to true
    checking2=true;
    break;
    }
    }

    //if user clicks on the save as rejected button, do the following queries
    if (check != null)
    {
    if(checking == false || checking2 == false)
    {
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET First_Name= '"+fnameU+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Last_Name= '"+lnameU+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Full_Name= '"+changefullname+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET AA_UserName= '"+AAname+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Email_Address= '"+emailL+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET SRStatus = \"Rejected\" where SRNo='" + changesrno + "' ");
    out.println("Data updated!!!");
    }
    else{out.println("Error. Duplicate name or email address founded");}
    }
    else{}

    //user clicks on the unreject button, do the following queries
    if (check2 != null)
    {
    //System.out.println("3"+checking);
    // System.out.println("4"+checking2);
    if(checking == false || checking2 == false)
    {
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET First_Name= '"+fnameU+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Last_Name= '"+lnameU+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Full_Name= '"+changefullname+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET AA_UserName= '"+AAname+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET Email_Address= '"+emailL+"' where SRNo='" + changesrno + "' ");
    rs = statement.executeQuery("UPDATE SR_MsgSvc_Creation SET SRStatus = \"Pending\" where SRNo='" + changesrno + "' ");
    out.println("Data updated!!!");
    }
    else{out.println("Error. Duplicate name or email address founded");}
    }
    else{}

    %>
    <!--close the connection to database, resultset and statement-->
    <%
    rs.close();
    rs2.close();
    rs3.close();
    statement.close();
    connection.close();
    %>

    how come i encounter a null pointer exception error???
    pls help...
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    That's a lot of code...
    What line is the error being thrown on? (And what's on that line?)
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0
    i found out that it does not go into the second if statement which is :
    if(checking == false || checking2 == false)

    this line actually checks for if there are any duplicate name and email address that the user entered.

    Pls reply asap...

IMN logo majestic logo threadwatch logo seochat tools logo