1

--> 好的,我在 SD 卡中有一个 Sq-lite 数据库。

  (String DB_PATH = Environment.getExternalStorageDirectory().getPath().toString();)

--> 检查数据库是否存在

        dbFile = new File(DB_PATH + DB_NAME );
        if(dbFile.exists()== true)
        {
            //set text db exists
            open_DB();

        }
        else 
        {
            //set text db does not exist
            return;
        }

--> 在调试时我可以确认数据库文件的存在。但是打开
数据库时出现异常

    SQLiteDatabase checkDB = null;
    try 
    {
        dbFile = new File(DB_PATH + DB_NAME);
        myDataBase = SQLiteDatabase.openOrCreateDatabase(dbFile, null);

        //myDataBase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, 0);
        //also tried this

        //set text bd opened
    }
    catch(SQLiteException e) 
    {
        //set text bd unable open
        return;
    }
4

1 回答 1

0

可能您的问题是由标志或文件引起的,因此请尝试使用:

dbFile = new File(DB_PATH + DB_NAME);
if (dbFile.exists()) {
   db = SQLiteDatabase.openDatabase(db_path, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.CREATE_IF_NECESSARY);
}

让我知道。

于 2013-02-22T08:49:05.280 回答