检查android中的数据库是否为空

时间:2012-06-28 21:19:27

标签: android sqlite

  

可能重复:
  How can i check to see if my sqlite table has data in it?
  Android check if database is empty

有人能告诉我如何检查sqlite数据库(在android中)是空的还是有表,如果它有表是空的还是有值?

我使用sqlite制作了一个登录验证程序,我希望它检查是否没有用户自动登录

1 个答案:

答案 0 :(得分:1)

您可以使用简单的方法检查数据库是否已存在。

private boolean checkDataBase(){

    SQLiteDatabase checkDB = null;

    try{
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
    } catch(SQLiteException e){ 
        //database doesn't exist yet
    }

    if(checkDB != null){
        checkDB.close();
    }

    return checkDB != null ? true : false;
}
相关问题