Check If Data Is Exist In Sqlite Android
I use this function to get specific data from SQlite: SearchRes getSresultByName(String name) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TA
Solution 1:
you should not be checking if cursor is null you should be checking if anything exists in the cursor
if(cursor.moveToFirst()){
returntrue
}else{
returnfalse;
}
Solution 2:
You can try Cursor
getCount() to check the number of rows in the result of the query.. Following is the sample code:
booleancheckIfExist(String name) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_WIKIRES, newString[] { KEY_ID,
KEY_SNAME, KEY_SJSON }, KEY_SNAME + "=?",
newString[] { name }, null, null, null, null);
if (cursor.getCount() > 0)
returntrue;
elsereturnfalse;
}
answer by @tyczj is also good..
Post a Comment for "Check If Data Is Exist In Sqlite Android"