开发者

why isnt this database query working correctly

I am trying to search my database to see if a number exists in it, return true if it does and false if not. here is my query

    public boolean getPhone(String where){
    Cursor cur = db.query(DATABASE_TABLE, new String [] {ID,PHONE_NUMBER},PHONE_NUMBER + "='" + where + "'",null,null,null,null);

        if(cur.moveToFirst()){

            do{
                String test = cur.getString(cur.getColumnIndex(PHONE_NUMBER));
                Log.v("ContactDB", test);
  开发者_如何学C              if(test.equals(where))
                    return true;

             }while(cur.moveToNext());
        }
            return false;
    }

when it gets to the do while loop it jumps right over it to return false without even doing it once like it should. If I take the do while loop out, the if(c.movetofirst()) tests false im guessing because that also jumps right to return false.

I just dont get why it is not working right. the database exists and has values in it


Your cur.moveToFirst() is returning false, meaning that there is no data in the cursor. As for why, I would venture to guess that your database does not contain the data that you are passing into this method. You should drop a debug in there to verify you are passing in the value that you expect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜