How to check existing database before creating new database on android 2.2?

前端 未结 4 759
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 12:48

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

4条回答
  •  悲哀的现实
    2021-01-22 13:14

    use openOrCreateDatabase method

    Read here

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

提交回复
热议问题