How to prevent to insert duplicate value in sqlite database (if duplicate then overwrite)

前端 未结 6 1276
余生分开走
余生分开走 2021-01-05 15:34

I had created two table in my database, In both table I am inserting value at the same time, now what I want to do is that, I want to insert record in second table, but the

6条回答
  •  猫巷女王i
    2021-01-05 16:34

    This is working for me,and i also created Category as a primary key..

    ContentValues Val = new ContentValues();
    Val.put("IDD", idd); 
    Val.put("Category", cat);
    long rows=db.insertWithOnConflict(TABLE_CATEGER, null,  Val,SQLiteDatabase.CONFLICT_REPLACE);
    System.out.print(rows);
    Log.d("kkkkkkkkkk",""+ rows);
    db.close();
    return rows; // return rows inserted.
    

提交回复
热议问题