Android Sqlite: Check if row exists in table

后端 未结 2 1493
感动是毒
感动是毒 2020-12-17 03:23

I have an array of strings that need to be checked if exists in a table before inserting them in order to avoid duplicates. What is the SQL query and how do I substitute the

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-17 04:12

    Just do like

     Cursor cursor = null;
     String sql ="SELECT PID FROM "+TableName+" WHERE PID="+pidValue; 
     cursor= db.rawQuery(sql,null);
     Log("Cursor Count : " + cursor.getCount());
    
     if(cursor.getCount()>0){
      //PID Found
     }else{
     //PID Not Found 
     }
     cursor.close();
    

提交回复
热议问题