且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-25 14:58:34

使用 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;
}