我正在尝试读取存储在SDCard上的SQLite数据库。部分代码如下:
public String getTables() {
String dbFullPath = Environment.getExternalStorageDirectory().toString() + "/external_sd/database.db";
String query = "SELECT name from sqlite_master where type='table'";
SQLiteDatabase mDatabase = SQLiteDatabase
.openDatabase(dbFullPath, null, SQLiteDatabase.OPEN_READONLY
+ SQLiteDatabase.NO_LOCALIZED_COLLATORS);
Log.d(TAG, "Is db open? " + mDatabase.isOpen());
Cursor cursor = mDatabase.rawQuery(query, null);
String tables = cursor.getString(0);
cursor.close();
return tables;
}
但是,运行此代码时,我收到以下错误
java.lang.RuntimeException:无法启动活动ComponentInfo {...}:android.database.sqlite.SQLiteException:无法打开数据库文件:,同时编译:来自sqlite_master的SELECT名称,其中type ='table'
在Cursor cursor = mDatabase.rawQuery(query, null);
行。
调试日志返回Is db open? true
,这意味着我的路径正确并且数据库已成功打开?
答案 0 :(得分:0)
Cursor cursor = mDatabase.query(sqlite_master, new String[] { "name" }, "type=" + table, null,
null, null, "name asc");