title: android - prevent duplicate insert data in SQLite
body: <p>I just learned to use sqlite on android. how to prevent duplicate data when it will be inserted .. so, when there is same data entry, it will overwrite the data?</p>
  
  <p>here I attach the code snippet:</p>
  
  <pre><code>@Override
      public void onCreate(SQLiteDatabase db) {
          String CREATE_FAVORIT_TABLE = "CREATE TABLE " + Constant.favoritDBtable + "("
                  + Constant.id_postFav + " INTEGER PRIMARY KEY AUTOINCREMENT," + Constant.titleFav + " TEXT," + Constant.namaPerusahaanFav + " TEXT,"
                  + Constant.lokasiFav + " TEXT," + Constant.kriteria_1Fav + " TEXT," + Constant.kriteria_2Fav
                  + " TEXT," + Constant.kriteria_3Fav + " TEXT," + Constant.gajiFav + " TEXT," + Constant.img_logoFav
                  + " TEXT," + Constant.tanggalFav + " TEXT);";
  
  public String addFavorit(Favorit favorit){
          SQLiteDatabase db = this.getWritableDatabase();
  //        long rows = 0;
  
          ContentValues values = new ContentValues();
          values.put(Constant.titleFav, favorit.getTitleFav());
          values.put(Constant.namaPerusahaanFav, favorit.getNamaPerusahaanFav());
          values.put(Constant.lokasiFav, favorit.getLokasiFav());
          values.put(Constant.kriteria_1Fav, favorit.getKriteria_1Fav());
          values.put(Constant.kriteria_2Fav, favorit.getKriteria_2Fav());
          values.put(Constant.kriteria_3Fav, favorit.getKriteria_3Fav());
          values.put(Constant.gajiFav, favorit.getGajiFav());
          values.put(Constant.img_logoFav, favorit.getImg_logoFav());
          values.put(Constant.tanggalFav, favorit.getTanggalFav());
  
        db.insert(Constant.favoritDBtable, null, values,);
  
  Log.d("Favorit saved: ", "Success 200 OK");
          return null;
      }
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>@Override
      public void onClick(View v) {
  
          if (job.getTitle() != null &amp;&amp; job.getLokasi() != null){
          saveToFavoritDB();
          }
      }
  
      private void saveToFavoritDB() {
          Favorit favorit = new Favorit();
  
          favorit.setTitleFav(job.getTitle());
          favorit.setGajiFav(job.getGaji());
  
          Log.d(TAG, "gaji " + job.getGaji());
  
          db.addFavorit(favorit);
  
          List&lt;Favorit&gt; favList = db.getAllFavorit();
  
          for (Favorit each : favList) {
              String log = "ID: " + each.getTitleFav() + ", Name: " + each.getLokasiFav() + ", Phone: " + each.getGajiFav();
              Log.d(TAG, "saveToFavoritDB: " + String.valueOf(db.getCountFavorit()));
              Log.d(TAG, "Hasil: " + log);
          }
      }
  </code></pre>
  
  <p>hope you can help me</p>