Android - 无法打开数据库(SQLite)

时间:2017-08-27 14:08:57

标签: java android sqlite

我正在创建一个数据库导出器库。我从提供的上下文中获取整个数据库

 mContext.databaseList() //return String[] of databases

然后使用循环

获取每个数据库
  File databasePath = mContext.getDatabasePath(databaseName);
        SQLiteDatabase db = SQLiteDatabase.openDatabase(databasePath.getAbsolutePath(), null, 0);

出于测试目的,我使用了一个实时项目,然后我注意到一个我没有创建的数据库叫做

SLM_B.db-journal.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back

当我尝试打开这个数据库时,我遇到了这个问题。

Failed to open database '/data/user/0/com.samsung.lighting/databases/SLM_B.db-journal.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back.back'.
                  android.database.sqlite.SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode
                  #################################################################
                  Error Code : 26 (SQLITE_NOTADB)
                  Caused By : File opened that is not a database file or encrypted.
                    (file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode)
                  #################################################################
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1009)
                      at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:713)
                      at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:387)
                      at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:361)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:250)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:201)
                      at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:514)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
                      at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:934)
                      at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:708)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:683)
                      at com.godwin.databasedebugger.DatabaseExporter.exportDB(DatabaseExporter.java:41)
                      at com.godwin.databasedebugger.TableListFragment.exportDatabase(TableListFragment.java:55)
                      at com.godwin.databasedebugger.TableListFragment.onViewCreated(TableListFragment.java:50)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1314)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                      at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                      at android.app.Activity.performStart(Activity.java:6943)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                      at android.app.ActivityThread.access$1100(ActivityThread.java:230)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1822)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:7409)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
08-27 19:24:32.801 E: file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode
                  #################################################################
                  Error Code : 26 (SQLITE_NOTADB)
                  Caused By : File opened that is not a database file or encrypted.
                    (file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode)
                  #################################################################
                  android.database.sqlite.SQLiteDatabaseCorruptException: file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode
                  #################################################################
                  Error Code : 26 (SQLITE_NOTADB)
                  Caused By : File opened that is not a database file or encrypted.
                    (file is encrypted or is not a database (code 26): , while compiling: PRAGMA journal_mode)
                  #################################################################
                      at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                      at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:1009)
                      at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:713)
                      at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:387)
                      at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:361)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:250)
                      at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:201)
                      at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:514)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:206)
                      at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
                      at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:934)
                      at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:898)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:708)
                      at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:683)
                      at com.godwin.databasedebugger.DatabaseExporter.exportDB(DatabaseExporter.java:41)
                      at com.godwin.databasedebugger.TableListFragment.exportDatabase(TableListFragment.java:55)
                      at com.godwin.databasedebugger.TableListFragment.onViewCreated(TableListFragment.java:50)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1314)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1528)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1595)
                      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:758)
                      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2363)
                      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2149)
                      at android.support.v4.app.FragmentManagerImpl.optimizeAndExecuteOps(FragmentManager.java:2103)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2013)
                      at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:388)
                      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:607)
                      at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
                      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
                      at android.app.Activity.performStart(Activity.java:6943)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3277)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3416)
                      at android.app.ActivityThread.access$1100(ActivityThread.java:230)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1822)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:7409)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
                    at com.andr
  

我的问题是

     
      
  1. 为什么这个数据库?
  2.   
  3. 其他类型的应用程序是否有类似的内容?
  4.   
  5. 如何避免这种情况? (比字符串比较)
  6.   
  7. 如何加密或解密自己的数据库?
  8.   

0 个答案:

没有答案