我编写了一个rssFeedReader应用程序并直接使用sqliteSyntax来修改数据库。 这是我的代码:
database.execSQL database= openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
database.execSQL("Create TABLE IF NOT EXISTS Press (press_name
VARCHAR, press_url VARCHAR");
database.execSQL("INSERT INTO Press VALUES ('Tasnim',
'http://www.tasnimnews.com/english/rss/feed/?d=2&c=1&m=6&alt=Recent%20News');");
database.execSQL("UPDATE Press press_name ='Tasnim',
press_url ='http://www.tasnimnews.com/english/rss/feed/?
d=2&c=1&m=6&alt=Recent%20News');");
Cursor cursor = database.rawQuery("SELECT * FROM MyTable", null);
database.close();
现在我的问题是如何迁移到 SQLiteOpenHelper 和 ConentValues 方法来修改数据库。
答案 0 :(得分:0)
// Gets the data repository in write mode
SQLiteDatabase db = mDbHelper.getWritableDatabase();
// Create a new map of values, where column names are the keys
ContentValues values = new ContentValues();
values.put(FeedEntry.COLUMN_NAME_ENTRY_ID, id);
values.put(FeedEntry.COLUMN_NAME_TITLE, title);
values.put(FeedEntry.COLUMN_NAME_CONTENT, content);
// Insert the new row, returning the primary key value of the new row
long newRowId;
newRowId = db.insert(
FeedEntry.TABLE_NAME,
FeedEntry.COLUMN_NAME_NULLABLE,
values);
您可以在http://developer.android.com/training/basics/data-storage/databases.html
找到它