Insert data into database
suggest change// You need a writable database to insert data
final SQLiteDatabase database = openHelper.getWritableDatabase();
// Create a ContentValues instance which contains the data for each column
// You do not need to specify a value for an INTEGER PRIMARY KEY column.
// SQLite generates the rowid when that column is omitted.
final ContentValues values = new ContentValues();
values.put(COLUMN_NAME, model.getName());
values.put(COLUMN_DESCRIPTION, model.getDescription());
values.put(COLUMN_VALUE, model.getValue());
// This call performs the insert.
// The return value is the rowId or primary key value for the new row.
// If this method returns -1 then the insert has failed.
final long id = database.insert(
TABLE_NAME, // The table name in which the data will be inserted
null, // String: optional; may be null. If your provided values is empty,
// no column names are known and an empty row can't be inserted.
// If not set to null, this parameter provides the name
// of nullable column name to explicitly insert a NULL
values // The ContentValues instance which contains the data
);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents