Skip to content

Instantly share code, notes, and snippets.

@msdalp
Created March 1, 2014 19:21
Show Gist options
  • Save msdalp/9295603 to your computer and use it in GitHub Desktop.
Save msdalp/9295603 to your computer and use it in GitHub Desktop.
public synchronized boolean setData(List<YourObject> _objects) {
final SQLiteDatabase db = this.getWritableDatabase();
final String INSERT_DATA = "INSERT INTO table_data VALUES (?,?,?,?);";
boolean retval = false;
try {
db.delete(SQL.TABLE_DATA, null, null);
SQLiteStatement statement = db.compileStatement(INSERT_DATA);
db.beginTransaction();
for (YourObject object : _objects) {
statement.clearBindings();
statement.bindLong(1, object.id);
statement.bindString(2, object.name);
statement.bindString(3, object.abbr);
statement.bindLong(4, object.foundYear);
statement.execute();
}
db.setTransactionSuccessful();
db.endTransaction();
retval = true;
} catch (Exception ex) {
Log.e(TAG, "setData 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