你是如何在數據庫查詢?
正確的方法不是在代碼中放置單獨的數據庫,而是動態創建一個數據庫。對於例如以下代碼:
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSql("/*Put Create Table sqls here*/");
//onCreate will be called only once(when db doesn't exists for application, it creates here with the code)
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
在代碼中使用這樣的數據庫輔助類。
現在,只要你想在你的數據庫查詢,你可以做這樣的:
dbHelper = new DatabaseHelper(ctx);
db = dbHelper.getWritableDatabase();
//Start querying on db.(if it is not created oncreate() of dbhelper will create it for you.
所以,簡單地把你的初始數據庫創建OnCreate中)dbhelper
的,/ insert語句(