【发布时间】:2012-01-02 04:53:32
【问题描述】:
我将“food_db.sql”文件存储在 /res/raw 文件夹中, 它有大量的“插入”。
我的问题是如何在我的 android 应用程序中执行文件并将数据导入 sqlite 数据库?
这是我的数据库代码。有什么建议吗?
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
KEY_NAME + " TEXT NOT NULL, " +
KEY_HOTNESS + " TEXT NOT NULL);");
// how do i exec the sql file and get the data into this DB table?
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS" + DATABASE_TABLE);
db.execSQL("DROP TABLE IF EXISTS" + RECORD_TABLE);
onCreate(db);
}
}
【问题讨论】:
标签: android sql database sqlite