dimanche 21 décembre 2014

How to check wheter there is a record satisfying some condition in a sqlite table

I have the following code



public int getIngCount(String id,String ingrediant) {
String countQuery = "SELECT * FROM " + TABLE_CONTACTS2 + " WHERE id = "+id+ " AND ingrediant = "+ingrediant;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();

// return count
return cursor.getCount();

}


But when there is no records satisfying the condition, it causing an exception instead of returning 0.


pls help me to find a solution. Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire