查询如果Android的数据库存在! [英] Query if Android database exists!
本文介绍了查询如果Android的数据库存在!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了我的Android应用程序的数据库,其中包含静态数据,并且不需要更新/删除功能,因此应用程序启动时,我要检查,如果该数据库存在,如果没有的话执行我的dbAdapter类。我知道它的一个简单的if语句,但我只是想知道最有效的方式来查询数据库是否存在。
干杯
解决方案
/ **
*检查是否存在于数据库中,可以读出。
*
* @返回true,如果它存在,并且可以读取,假的,如果它不
* /
私人布尔checkDataBase(){
SQLiteDatabase CHECKDB = NULL;
尝试 {
CHECKDB = SQLiteDatabase.openDatabase(DB_FULL_PATH,空,
SQLiteDatabase.OPEN_READONLY);
checkDB.close();
}赶上(SQLiteException E){
//数据库不存在。
}
返回CHECKDB!= NULL;
}
在这里DB_FULL_PATH是路径到你的数据库文件
I have created a database for my android app which contains static data and does not require update/delete functionality thus when the app starts, I want to check if the db exists and if not then execute my dbAdapter class. I know its a simple if statement but I was just wondering the most efficient way to query whether the db exists.
Cheers
解决方案
/**
* Check if the database exist and can be read.
*
* @return true if it exists and can be read, false if it doesn't
*/
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
checkDB = SQLiteDatabase.openDatabase(DB_FULL_PATH, null,
SQLiteDatabase.OPEN_READONLY);
checkDB.close();
} catch (SQLiteException e) {
// database doesn't exist yet.
}
return checkDB != null;
}
where DB_FULL_PATH is the path to your database file
这篇关于查询如果Android的数据库存在!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文