David_Zhuo
发贴: 16
|
于 2012-02-22 16:54
String DB_PATH = "/data/data/com.mycompany.worldclock/databases/"; String dbName = "world_time.db"; String myPath = DB_PATH + dbName; SQLiteDatabase theDatabase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
// theDatabase.query("data", new String[] {KEY_CITY, KEY_TIMEZONE, // KEY_COUNTRY, KEY_TIMEZONE_DISPLAY_NAME, // KEY_TIMEZONE_ID},_ID+" = '"+id+"';", null, null, null, null, // null);
final String _ID = "_id"; final String DATABASE_TABLE = "data"; final String KEY_CITY = "city"; final String KEY_COUNTRY = "country"; final String KEY_TIMEZONE = "timezone"; final String KEY_TIMEZONE_DISPLAY_NAME = "display_name"; final String KEY_TIMEZONE_ID = "timezone_id"; String s = "(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi"; Cursor c; try { c = theDatabase.query("data", new String[] { KEY_CITY, KEY_TIMEZONE, KEY_COUNTRY, KEY_TIMEZONE_DISPLAY_NAME, KEY_TIMEZONE_ID, _ID }, null, null, null, null, null, null); int count = c.getCount(); c.moveToFirst(); for (int i = 0; i < count; i++) { System.out.println("city:" + c.getString(0)); System.out.println("timezone:" + c.getString(1)); System.out.println("country:" + c.getString(2)); System.out.println("display_name:" + c.getString(3)); System.out.println("timezone_id:" + c.getString(4)); System.out.println("_id:" + c.getString(5)); Test test = new Test(); ContentValues contentValues = new ContentValues(); contentValues.put("city", test.getStringValue(c.getString(0))); contentValues.put("timezone", test.getStringValue(c.getString(1))); contentValues.put("country", test.getStringValue(c.getString(2))); contentValues.put("display_name", test.getStringValue(c.getString(3))); contentValues.put("timezone_id", test.getStringValue(c.getString(4))); theDatabase.update("data", contentValues, "_id=?",new String[]{test.getStringValue(c.getString(5))} ); c.moveToNext(); } c.close(); } catch (Exception e) { Log.e(TimelyPiece.WORLD_CLOCK, "Error getting Timezone for " + KEY_CITY + " : " + e.getMessage()); }
|