我已经知道如何创建Sqlite数据库了。关键是数据库文件仅在内部存储(/ data / {package name})
中创建有没有办法直接在外部存储上创建Sqlite数据库?
答案 0 :(得分:2)
您可以像这样创建数据库:
private SQLiteDatabase db;
private yourPath = "/mnt/sdcard/";
private SQLiteDatabase db = openOrCreateDatabase(yourPath + "sudoku.db", Context.MODE_PRIVATE, null);
修改您的方法:
private static Cursor query(String query) {
if (query != null) {
openDB();
while (db.isDbLockedByCurrentThread()) {
// db in use, keep looping
}
Log.d("Query", query);
return db.rawQuery(query, null);
} else {
return null;
}
}
private static void openDB() {
if (db == null) {
db = SQLiteDatabase.openDatabase(yourPath + "sudoku.db", null, SQLiteDatabase.OPEN_READWRITE);
}
}