I have a table on a database with two columns, and then i am trying to use webservice,JSON parse some data from some URL to the database and save it. I try to do that in this method
public void saveDataRecord(String id, String name) {
ContentValues contentValues = new ContentValues();
contentValues.put(CATEGORY_COLUMN_ID, id);
contentValues.put(CATEGORY_COLUMN_NAME, name);
database.insert(TABLE_NAME, null, contentValues);
}
However i am also having model class(which contain setter and getter), that can be use when i try to read data from database using list(it works on my previous object that have database inside and the values already inserted). Now i want to use that because it has the parameters and can be useful to read list(take a look at the bottom code). I am a bit confuse, what to use getId,getName or setId,setName?
this?
public void saveDataRecord(TheModelClass blablabla) {
ContentValues contentValues = new ContentValues();
contentValues.put(CATEGORY_COLUMN_ID, blablabla.getId());
contentValues.put(CATEGORY_COLUMN_NAME, blablalbla.getName());
database.insert(TABLE_NAME, null, contentValues);
}
or this?
public void saveDataRecord(TheModelClass blablabla) {
ContentValues contentValues = new ContentValues();
contentValues.put(CATEGORY_COLUMN_ID, blablabla.setId());
contentValues.put(CATEGORY_COLUMN_NAME, blablalbla.setName());
database.insert(TABLE_NAME, null, contentValues);
}
even tho i did this on my other project
public List<EntryEffectiveRate> getAllEffectiveRates() {
List<EntryEffectiveRate> EffectiveRates = new ArrayList<EntryEffectiveRate>();
String selectQuery = "SELECT * FROM " + TABLE_EFFECTIVE_RATE;
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (c.moveToFirst()) {
do {
EntryEffectiveRate ergt = new EntryEffectiveRate();
ergt.setERId(c.getInt(c.getColumnIndex(KEY_ER_ID)));
ergt.setERTenor(c.getInt(c.getColumnIndex(KEY_ER_TENOR)));
ergt.setERRate(c.getDouble(c.getColumnIndex(KEY_ER_RATE)));
// add
EffectiveRates.add(ergt);
} while (c.moveToNext());
}
// db.close();
c.close();
return EffectiveRates;
}
I am still confuse with what getter and setter do exactly
Aucun commentaire:
Enregistrer un commentaire