1

I wanted to compare the value of my String to my database values. But comparing them conditionally won't meet the requirements also I wrap this in try catch block and didn't throw any error. Already setText this in the TextView and gives the right value but comparing it won't compare.

Database:

public Cursor getUser(int id, String userPassword)
{
    open();                                                                                             //WHERE
    Cursor c = ourDatabase.query(true,DATABASE_TABLE, new String[] {"USER_ID","PASSWORD","POSITION"}, "USER_ID" + "=" + id + " " + "AND" + " " + "PASSWORD" + "=" + userPassword, null,null,null,null,null);

    return c;
}

public void onClick(View view)
        {
            try
            {
                UserDB userDB = new UserDB(Login.this);
                userDB.open();

                int id = Integer.parseInt(editTextUser.getText().toString());
                String password = editTextPassword.getText().toString();

                Cursor c = userDB.getUser(id, password);

                if (c.moveToFirst())
                {
                    do
                    {
                        String checkPosition = c.getString(c.getColumnIndex("POSITION"));
                        if(checkPosition == "Admin")
                        {
                            Toast.makeText(getApplicationContext(), "SUCCESS!", Toast.LENGTH_LONG).show();
                        }
                    }
                    while (c.moveToNext());
                    userDB.close();

                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }

        }
Francisunoxx
  • 1,440
  • 3
  • 22
  • 45

0 Answers0