如何在Android 2.2创建新的数据库之前,请检查现有的数据库?数据库、请检查、如何在、Android

2023-09-07 16:52:20 作者:霸气名字

我需要在Android 2.2创建新的数据库之前检查现有的数据库。如何检查呢?

I need to check existing database before creating new database on android 2.2. How to check it?

推荐答案

使用 openOrCreateDatabase 方法

这里阅读

-----编辑------

----- EDIT ------

public boolean checkDataBase(){

    SQLiteDatabase checkDB = null;

    try{
        String myPath = DB_PATH + DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);

    }catch(SQLiteException e){

        //database does't exist yet.
    }

    if(checkDB != null){
        checkDB.close();
    }

    return checkDB != null ? true : false;
}