1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| private long insertRecord(ContentValues contentValues) {
// Assign the values for each column.
contentValues.put(Constants.KEY_COL_NAME, "name");
contentValues.put(Constants.KEY_COL_FIRSTNAME, "firstName");
contentValues.put(Constants.KEY_COL_EYES_COLOR, "green");
contentValues.put(Constants.KEY_COL_HAIR_COLOR, "blond");
contentValues.put(Constants.KEY_COL_AGE, 6);
// Insert the line in the database
long rowId = db.insert(Constants.MY_TABLE, null, contentValues);
// Test to see if the insertion was ok
if (rowId == -1) {
Toast.makeText(this, "Error when creating an human",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Human created and stored in database",
Toast.LENGTH_LONG).show();
}
return rowId;
} |
Partager