【问题标题】:Android check a DB exists or notAndroid检查数据库是否存在
【发布时间】:2021-11-30 13:30:00
【问题描述】:
private SQLiteDatabase db = null;
private final String DB_NAME = "myDB";

我刚刚创建了一个数据库和表。我需要通过单击另一个按钮来检查是否存在 db。

db = this.openOrCreateDatabase("myDB", MODE_PRIVATE, null);

【问题讨论】:

    标签: android database sqlite android-sqlite


    【解决方案1】:

    可以检查数据库文件是否存在;您可以使用getDataBasePath() 获取数据库File 对象:

        File dbFile = getDatabasePath(DATABASE_NAME); // add the database file name like "myDatabase.db"
    
        if (dbFile.exists())
            Log.d("LOG_TAG", "Database exists");
        else
            Log.d("LOG_TAG", "Database doesn't exists");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-08
      • 2019-06-24
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多