开发者

checking database in android

I h开发者_开发百科ave to check whether a database exists or not in android?? how can i check? It should return a boolean value after checking?plz provide me with the code.


Something like:

private boolean databaseExists() {
    SQLiteDatabase checkDB = null;
    try {
        String myPath = DB_PATH + DATABASE_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READONLY);
        if(checkDB != null){
            checkDB.close();
            return true;
        } else {
            //database does not exist
            return false;
        }
    } catch (SQLiteException e) {
        //database does not exist
        return false;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜