判断android SQLite中的表是否为空

来源:互联网 发布:windows 搭建owncloud 编辑:程序博客网 时间:2024/06/05 18:53

SQLite中的Cursor千万不能使用Cursor == null 来判断是否为空,即便Cursor中什么记录都没有,他也不会是空(已测试)。

判断是否为空的方法是 Cursor.getCount()这么一个简单的函数,如果是0,表示Cursor为空;如果非0,则表示Cursor不为空。

代码如下

int number=0;
Cursor c = db.rawQuery("select * from table", null);
number=c.getCount();

0 0