-1
public boolean check()
    {
      db=SQLiteDatabase.openDatabase("Hotels",null,SQLiteDatabase.OPEN_READONLY);
        String query="Select * from hot where email='x'  and phone='w'";
        Cursor c=db.rawQuery(query,null);
        if(c.getCount()>0)
            return true;
        else
            return false;
    }

Here I am trying to check whether the user with this name and mobile number exists or not.if it exists then it should return true otherwise false.Here Hotels is the name of database and hot is the name of table.

Sumit Kapoor
  • 1,089
  • 12
  • 10

1 Answers1

-1

I guess you will face cursorindexoutofboundException maybe. You are trying to check whether exists or not however if there are no any datum inside your db, you will get an error.

Use if(c!=null && c.getCount()!=0) instead of (c.getCount()>0);

The Dongster
  • 337
  • 1
  • 3
  • 15