would anyone please take a quick look? this always return false for some reason... the database connection is fine and the query is fine... it actually returned the right password from the database. please see below

public boolean passCheck(String login, String pass)
	{
		String realPass="";
		
		try
		{
			String query ="SELECT password FROM admin_user where login_name='"+login+"'";
			resultSet = statement.executeQuery(query);
            while ( resultSet.next() ) 
            {
                realPass = resultSet.getString("password");
                System.out.println(realPass);
            }
			
		}
		catch(SQLException sqlex)
		{
			sqlex.printStackTrace();
		}
                // the returned password is correct
		System.out.println("from db pass is "+realPass);
		// this matches the password from above
                System.out.println("entered pass is "+pass);
		if(pass == realPass)
		{
			return true;
		}
		
		else
		{
			return false;
		}
	}

please point out why this function always return "false" ... thanks very much

always forgot string has to be compared by .equals() method....

Try this and let me now:

public boolean passCheck(String login, String pass) {
        boolean found=false;
        try {
            String query = "SELECT password FROM admin_user where login_name='" + login + "'";
            // resultSet = statement.executeQuery(query);
            while (resultSet.next()) {
                realPass = resultSet.getString("password");
                System.out.println(realPass);


                if (pass == realPass) {
                    found =true;
                    break;
                } 
                
            }

        } catch (SQLException sqlex) {
            sqlex.printStackTrace();
        }
        // the returned password is correct
        System.out.println("from db pass is " + realPass);
        // this matches the password from above
        System.out.println("entered pass is " + pass);
        /*if (pass == realPass) {
        return true;
        } else {
        return false;
        }*/
        return found;
    }

Try this and let me now:

...
                if (pass == realPass) {
                    found =true;
                    break;
                } 
   ...

hmmm... why this answer? not only did k2k found (and posted) the right answer himself, but your answer is wrong.
if you use Java on a regulary basis, you should know by now that it is an Object Oriented language, that a String is an Object and that Objects are compared not by '==' but by the .equals(Object b) method.

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.