如何在Android 2.2创建新的数据库之前,请检查现有的数据库? [英] How to check existing database before creating new database on android 2.2?
本文介绍了如何在Android 2.2创建新的数据库之前,请检查现有的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Android 2.2创建新的数据库之前检查现有的数据库。如何检查呢?
I need to check existing database before creating new database on android 2.2. How to check it?
推荐答案
使用 openOrCreateDatabase
方法
<一个href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#openOrCreateDatabase%28java.lang.String,%20android.database.sqlite.SQLiteDatabase.CursorFactory%29"相对=nofollow>这里阅读
-----编辑------
----- 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;
}
这篇关于如何在Android 2.2创建新的数据库之前,请检查现有的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文