Skip to content

Instantly share code, notes, and snippets.

@msdalp
Created March 1, 2014 19:25
Show Gist options
  • Save msdalp/9295639 to your computer and use it in GitHub Desktop.
Save msdalp/9295639 to your computer and use it in GitHub Desktop.
public synchronized boolean addData(List<YourObject> _objects) {
final SQLiteDatabase db = this.getWritableDatabase();
boolean retval = false;
try {
for (YourObject object : _objects) {
ContentValues contentValues = new ContentValues();
contentValues.put("ID", object.id);
contentValues.put("DATA_ID", object.dataId);
contentValues.put("VALUE", object.value);
db.insert("data",null,contentValues);
// db.insertWithOnConflict("data", null, contentValues, SQLiteDatabase.CONFLICT_REPLACE);
}
retval = true;
} catch (Exception ex) {
Log.e(TAG, "addData exception", ex);
} finally {
db.close();
}
return retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment