This gives a compilation error " missing return statement"..
there is no sql error or such...where to put the return.???

private boolean checkpword(){

pasWd = pword.getText() ;

try{

  /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");

            while(pwrd.next()){

                if(pasWd.equals(pwrd.getString("Pword"))){

                    return true;
                }
                else{
                        return false;
                }
            } 

        }catch(SQLException e){ }
    }

What happens when pwrd.next() returns false? What is the return value then?

What happens when pwrd.next() returns false? What is the return value then?

Ah i got it...mmmm.... but It doesn't mattr in a while loop right?

i jst want to return this true or false values ...thats it...(seems quit simple but!!!! :( )

Well, you know what you intend, but the compiler does not. The compiler sees that you have declared the method boolean, but that if the while condition evaluates to false that there is no return value.

What, exactly, are you attempting to do with this method. I mean, I see what you are doing, but I don't know that it would actually do what you intended it to do.

OOPS ..i got that...thankx...i am jst tryin to retrieve passwords from data base and compare to the user input(pass word ). then jst to grant access or deny. thats it.... can giv me a clue how to do it with this same way?

Here it is the code fraction....

private boolean checkpword(){

    String usrNm = uname.getText();
    String pasWd = pass.getText();

try{

        ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");


        while(pwrd.next()){

            if(pasWd.equals(pwrd.getString("Pword"))){

                return true;

            }
            else{

                return false;
            }

        } 

    }catch(SQLException e){ }


}
/********loginCheck() method***********************/

private void Logincheck(){


                boolean log = checkpword();



        if (log == true)

                 {  

            //grant access
        mainPage main = new mainPage();
                }                                        


         }else{
                  JOptionPane.showMessageDialog(null,"Login Failed \n Please enter correct username & password","Invalid Enter",JOptionPane.ERROR_MESSAGE);

            }

    }

Personally, working with that framework, I would replace that while loop with

if ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword")))) {
    return true;
} else {
    return false;
}

Edit: And, of course, add some sort of log message, or something to that catch block. Also, you must also add a return false to that catch block, or throw an exception from the method, as, otherwise, in the case of an exception, there is still no return statement.

Personally, working with that framework, I would replace that while loop with

if ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword")))) {
    return true;
} else {
    return false;
}

Edit: And, of course, add some sort of log message, or something to that catch block. Also, you must also add a return false to that catch block, or throw an exception from the method, as, otherwise, in the case of an exception, there is still no return statement.

hmm....thankx a lott......i'll giv a though on that....
i understood the prob thankx again....

And, actually, I'm an idiot, as all you really need is

return ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword"))));

and a return false in the catch block, of course.

Edit: And add a finally block to close the resultset and the statement that created it, and probably the connection as well (if using a connection pool, otherwise I assume you are using the same connection throughout the app).

wat da???...!!!!!!

wow ...is seems like we all are damn idiots!!!!! (meant only 4 me!!! :-D)

(by da way i am using the same connectn...)

thankx a lot 4 ur help...lokin 4wd 4 more.

hi just do the below changes

This gives a compilation error " missing return statement"..
there is no sql error or such...where to put the return.???

private boolean checkpword(){

boolean b=true;
pasWd = pword.getText() ;


try{

  /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");

            while(pwrd.next()){

                if(pasWd.equals(pwrd.getString("Pword"))){

                        b= true;
                }
                else{
                        b= false;
                }
            } 

        }catch(SQLException e){ }
                          return b;// error wiil clear
    }

end quote.

Why?

How is

private boolean checkpword(){
    boolean b=true;
    pasWd = pword.getText() ;

    try {
        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");
        while (pwrd.next()) {
            if (pasWd.equals(pwrd.getString("Pword"))) {
                b= true;
            } else {
                b= false;
            }
        }
    } catch(SQLException e) { }
    return b;// error wiil clear
}

better than

private boolean checkpword(){
    pasWd = pword.getText() ;

    try {
        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");
        try {
            return ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword"))));
        } finally {
            try { pwrd.close(); } catch (Exception ex) {}
            // close the statement
        }
    } catch(SQLException e) {
        // log the exception, at least
        return false;
    }
}

Other than ignoring the exception (which is probably indicative of a larger problem), leaving db resources hanging which will eventually "kill" the app, and creating extra memory management that is completely unnecessary?

Who told

Help with Code Tags Java Syntax (Toggle Plain Text)

private boolean checkpword(){    boolean b=true;    pasWd = pword.getText() ;     try {        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");        while (pwrd.next()) {            if (pasWd.equals(pwrd.getString("Pword"))) {                b= true;            } else {                b= false;            }        }    } catch(SQLException e) { }    return b;// error wiil clear}private boolean checkpword(){
    boolean b=true;
    pasWd = pword.getText() ;

    try {
        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");
        while (pwrd.next()) {
            if (pasWd.equals(pwrd.getString("Pword"))) {
                b= true;
            } else {
                b= false;
            }
        }
    } catch(SQLException e) { }
    return b;// error wiil clear
}

is better than

Help with Code Tags Java Syntax (Toggle Plain Text)

    private boolean checkpword(){    pasWd = pword.getText() ;     try {        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");        try {            return ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword"))));        } finally {            try { pwrd.close(); } catch (Exception ex) {}            // close the statement        }    } catch(SQLException e) {        // log the exception, at least        return false;    }}private boolean checkpword(){
    pasWd = pword.getText() ;

    try {
        /*this works ok...>>>*/ResultSet pwrd = c.getData("Select Pword from users where userNm = '"+uname.getText()+"' ");
        try {
            return ((pwrd.next()) && (pasWd.equals(pwrd.getString("Pword"))));
        } finally {
            try { pwrd.close(); } catch (Exception ex) {}
            // close the statement
        }
    } catch(SQLException e) {
        // log the exception, at least
        return false;
    }
}

I not here to tell whose code is best. I want to clear the problem up to my knowledge. And you completely changed the code and i just modified the code. Because at first when i saw the error "return" just i think to rectify the error by modifing. you changed the complete logic. I am not telling your's wrong and myself right, but i just think to clear the error. And i will try your code also to rectify the problem. Thank you.

No, I fixed the code. I have no problem with you trying to help, but I do have a problem with you providing seriously subpar "solutions" to something that has already been solved.

You would have been much better served to read the thread and try to understand what was being said rather than blindly plowing in with non-solutions that leave serious problems behind, when the real problems have already been solved.

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.