检查数据库中是否存在值

3D-*_*tiv 1 android

我想检查数据库中是否存在几个值.如果是,则如果游标为null,则该方法应返回TRUE或FALSE.但问题是尽管值不在数据库中,它仍会一直返回TRUE!我错过了什么?

    // This method check if the combination image path and contact name already exists in database
public boolean checkContentDatabase(String imageFilePath, String contactName) {

    String query = "Select * from " + DB_TABLE+ " where " + TABLE_IMAGE_PATH + "='" + imageFilePath + "' and " + TABLE_CONTACT_NAME + "='" + contactName +"' ;";

    Cursor c = db.rawQuery(query, null);

    if(c != null) // Exists in database
     {
     return true;
     }
     else
     {
         return false;
     }
}
Run Code Online (Sandbox Code Playgroud)

kdr*_*der 5

用以下内容替换if条件:

if(c.getCount() > 0)
 {
 return true;
 }
 else
 {
     return false;
 }
Run Code Online (Sandbox Code Playgroud)