lundi 25 avril 2016

SQLite database retrieval. Cant match strings [duplicate]

This question already has an answer here:

This is my code to check if the user has already registered. It checks if the same username password pair has been stored in the database. Even though I can see with the toast that's such a combination is their, I am always return "not found". What seems to be the problem here?

public String login(String user, String pass) {
            // TODO Auto-generated method stub
            int i=0;
            String[] columns = new String[]{KEY_NAME, KEY_USERN, KEY_PASS, KEY_EMAIL, KEY_CONT, KEY_EMER};
            Cursor c = ourDatabase.query(DATABASE_USER, columns, null, null, null, null, null);
            String res = "";
            int iQ1=c.getColumnIndex(KEY_USERN);
            int iQ2=c.getColumnIndex(KEY_PASS);
            Toast.makeText(ourContext, "1st"+user+pass, Toast.LENGTH_LONG).show();
            for(c.moveToFirst();!c.isAfterLast();c.moveToNext())
            {
                Toast.makeText(ourContext, "\'"+user+"\'"+c.getString(iQ1)+"\'"+pass+"\'"+c.getString(iQ2), Toast.LENGTH_LONG).show();
                if(c.getString(iQ2)==pass)
                {

                    Toast.makeText(ourContext,      c.getString(iQ1)+c.getString(iQ2), Toast.LENGTH_LONG).show();
                    return "found";
                }
                return "not found";

            }   

            return "not found";
        }

Aucun commentaire:

Enregistrer un commentaire