我可以导入或打开退出的SQLite文件(.db)到android项目吗?
我已经有.db文件,包含大量记录(约80,000条记录)
处理惠特的最佳方法是什么?怎么样?任何人都可以指导我!
答案 0 :(得分:2)
如果您问“如何将此现有SQLite数据库与我的应用程序一起发布,以用作用户的入门数据库?”,use SQLiteAssetHelper
:
首先,将您的数据库放在项目的assets/databases/
中(例如assets/databases/constants.db
)
接下来,保存一个提供数据库名称的SQLiteAssetHelper
的小子类:
/***
Copyright (c) 2008-2012 CommonsWare, LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License.
From _The Busy Coder's Guide to Android Development_
http://commonsware.com/Android
*/
package com.commonsware.android.dbasset;
import android.content.Context;
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
class DatabaseHelper extends SQLiteAssetHelper {
private static final String DATABASE_NAME="constants.db";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
}
}
最后,使用SQLiteAssetHelper
子类,就像使用SQLiteOpenHelper
的子类来获取数据库一样
(来自this sample project的代码)