我想将String的值与数据库值进行比较。但是比较它们有条件地不符合要求,我也将其包装在try catch block
中并且没有抛出任何错误。 setText
中TextView
已经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();
}
}
,并给出了正确的价值但是比较它不会比较。
数据库:
{{1}}