m new to android. When i m using db.query to retrieve and compare username it always returning some value
it have to return null when value not matches.
here is code
public boolean check(String name)
{
SQLiteDatabase db = DB.getReadableDatabase();
Cursor cursor = null;
try{
cursor=db.rawQuery("SELECT * FROM "+ DBHelper.Login_Table + " WHERE "+
DBHelper.KEY_USERNAME + "='" + name + "'",null);
}
catch(Exception e)
{
e.printStackTrace();
}
if (cursor!=null) {
Log.i("someTAG","Error .. USERNAME EXIST");
cursor.moveToFirst();
return true;
}
else
{
Log.i("someTAG","Error .. NOT EXIST");
return false;
}
}
No, your cursor does not have to return null, it just has to return 0 records.