Example #1
0
 /** 将Province实例存储到数据库。 */
 public void saveProvince(Province province) {
   if (province != null) {
     ContentValues values = new ContentValues();
     values.put("province_name", province.getProvinceName());
     values.put("province_code", province.getProvinceCode());
     db.insert("Province", null, values);
   }
 }
Example #2
0
 /** 从数据库读取全国所有的省份信息。 */
 public List<Province> loadProvinces() {
   List<Province> list = new ArrayList<Province>();
   Cursor cursor = db.query("Province", null, null, null, null, null, null);
   if (cursor.moveToFirst()) {
     do {
       Province province = new Province();
       province.setId(cursor.getInt(cursor.getColumnIndex("id")));
       province.setProvinceName(cursor.getString(cursor.getColumnIndex("province_name")));
       province.setProvinceCode(cursor.getString(cursor.getColumnIndex("province_code")));
       list.add(province);
     } while (cursor.moveToNext());
   }
   return list;
 }