Thread: return error.

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

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0

    return error.


    while(rs2.next())
    {
    full_name = rs2.getString(1);
    if(full_name.equalsIgnoreCase(changefullname))
    {

    return true;
    }
    else
    {
    return false;
    }
    }

    my error is:'return' with value from void
    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
    You need:

    public boolean function( String changefullname ) {

    ...

    }

    or something like that.
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0
    but i am doing jsp. how do i add the statement that u mentioned...

    is there another way???
  6. #4
  7. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2002
    Posts
    19
    Rep Power
    0
    i have changed to smthing like this however, even when there is a similiar record in the database, it still adds.

    <%
    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 Full_Name from SR_MsgSvc_Creation");
    //check if full name exist
    while(rs2.next())
    {
    full_name = rs2.getString(1);
    if(full_name.equalsIgnoreCase(changefullname))
    {
    //if exist, set checking to true
    checking=true;
    break;
    }
    //if not exist, set checking to false
    else
    {
    checking=false;
    break;
    }
    }

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

    //if user clicks on the save as rejected button, do the following queries
    if (check != null)
    {
    //System.out.println("1"+checking);
    //System.out.println("2"+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 = \"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();
    %>
  8. #5
  9. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You can only return a value from a function. You're not using a function, so no return. As for your code, it will run faster if you do your check in the SQL statement, rather than with java. Something like:
    Code:
     rs2 = statement.executeQuery("SELECT Full_Name FROM SR_MsgSvc_Creation WHERE Full_Name = " + changefullname);
    If rs2 has any records in it, then the value already exists. This will execute faster than getting all of the records and looking for the value yourself.

IMN logo majestic logo threadwatch logo seochat tools logo