2

How to check whether the value is inserted or not in Android?

I want to display

if inserted==true
   return true;
else
   return false;

This is my code:

SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
sqLiteDatabase.execSQL("INSERT INTO user VALUES (1,1,1,'admin','admin','21232f297a57a5a743894a0e4a801fc3','9986058114','8897456588','admin@admin.com','','Active','AD','admin')");
doptimusprime
  • 9,115
  • 6
  • 52
  • 90

2 Answers2

1

Check By DataBase : https://stackoverflow.com/a/21151598/8448886

You can also use Log to check data is inserted on or not on your DataBaseHelper class.

  public boolean addData(String name , String sku, String upc , String price, String displaySize, int displaySizeYes, String status){
    db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(Constants.NAME, name );
    contentValues.put(Constants.SKU, sku );
    contentValues.put(Constants.UPC, upc );
    contentValues.put(Constants.PRICE, price );
    contentValues.put(Constants.DISPLAY_SIZE, displaySize );
    contentValues.put(Constants.DISPLAY_SIZE_YES, displaySizeYes );
    contentValues.put(Constants.STATUS, status );

    long result = db.insert(Constants.TABLE_NAME,null,contentValues);
    Log.e(TAG,""+upc+"  Inserted");

    if(result == -1) {
        return false;
    }else{
      //  Log.e(TAG,"value inserted");
        return true;
    }

}
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44
0
public int numberOfRowsRecord() {
    db =  this.getReadableDatabase();
    return (int) DatabaseUtils.queryNumEntries(db, RECORD_TABLE_NAME);
}

Add this code in your helper class

this function return either number of row affected by this...

so you can check you value is inserted or not...

Rajan singh
  • 39
  • 1
  • 4