检查数据库采用的是Android空 [英] check if database is empty in android

查看:98
本文介绍了检查数据库采用的是Android空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/4397757/how-can-i-check-to-see-if-my-sqlite-table-has-data-in-it\">How我可以检查,看看我的SQLite表中有数据?结果
   Android的检查,如果数据库是空的

任何人能告诉我如何检查是否SQLite数据库(Android中)为空或有表,如果有表是空的或具有价值?

Can anybody tell me how to check if sqlite database (in android) is empty or has tables and if it has tables is it empty or has values?

我做了使用SQLite的登录验证程序,我想它来检查,​​如果没有用户自动登录

I made a login authentication program using sqlite and I want it to check if there is no users to log in automatically

推荐答案

您可以做一个简单的方法检查是否数据库alredy存在。

You can make a simple method checking if database alredy exists.

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

这篇关于检查数据库采用的是Android空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆