SQLite无法在频繁的“SELECT”查询中打开数据库文件(代码14)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLite无法在频繁的“SELECT”查询中打开数据库文件(代码14)相关的知识,希望对你有一定的参考价值。

我有以下类“Singleton”来处理SQLite连接并确保整个进程/ app有1个连接实例:

public class DBController {
  private static DBController instance = new DBController();
  private static DBHelper dbHelper;
  public static DBController getInstance()
  {
    return instance;
  }
  public SQLiteDatabase dbOpen(Context context)
  {
    if(dbHelper == null)
        dbHelper = new DBHelper(context);
    return dbHelper.getWritableDatabase();
  }
}

而DBHelper类本身:

public class DBHelper extends SQLiteOpenHelper {

  public DBHelper(Context context) {
    super(context, "database.db", null, 1);
  }
  @Override
  public void onCreate(SQLiteDatabase db) {
    final String position = "CREATE TABLE test (" +
            "test TEXT NOT NULL);";
    db.execSQL(position);
  }
}

当我经常尝试从数据库“选择”一些信息时,我收到以下错误:

SQLiteLog: (14) cannot open file at line 31278 of [2ef4f3a5b1]
SQLiteLog: (14) os_unix.c:31278: (24) open(/data/user/0/uz.mycompany.myapp/databases/database.db-journal) - 
SQLiteLog: (14) cannot open file at line 31278 of [2ef4f3a5b1]
SQLiteLog: (14) os_unix.c:31278: (24) open(/data/user/0/uz.mycompany.myapp/databases/database.db-journal) - 
SQLiteLog: (14) statement aborts at 29: [SELECT * FROM test WHERE test='testdata1'] unable to open database file
SQLiteQuery: exception: unable to open database file (code 14); query: SELECT * FROM test WHERE test='testdata1'
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14)

我正在运行以下代码来执行查询:

public String getData(Context context)
{
    SQLiteDatabase _db = dbOpen(context);
    Cursor c = _db.rawQuery("SELECT * FROM test WHERE test='testdata1'", null);
    return getDataFromCursor(c).get(0); //gets data from cursor and returns first one
}

如何管理/改进我的数据库连接以克服/避免此问题?

以上是关于SQLite无法在频繁的“SELECT”查询中打开数据库文件(代码14)的主要内容,如果未能解决你的问题,请参考以下文章

iOS的SQLite利用FMDB进行操作时无法打开数据库

SQLite INSERT SELECT 查询结果到现有表中?

在select查询中解决SQLite参数限制

增强 select sqlite 查询的性能

在 Ionic2 v3.4 中读取 SQLite SELECT 查询的结果

Android SQLite SELECT 查询