SQLite的计算范例 [英] SQLite count example

查看:115
本文介绍了SQLite的计算范例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的SQLite在Android中。 我有查询,查询执行以及如何从光标打印计数。

I am using SQLite in Android. I have the query, query executed and how to print count from cursor.

Cursor dataCount = mDb.rawQuery("select count(*) from " + DATABASE_JOURNAL_TABLE, null);

我在表中没有记录。

I have no record in table.

推荐答案

可以通过的调用getInt(指数)

cursor.getInt(1); // this is for example, you have to adjust index in your code

此外光标有一个内置的功能 getCount将() 返回行数,以便还可以这样做:

Also cursor has a built in function getCount() to return row number so can also do like this:

// assuming your table has `id` column as primary key or unique key.
Cursor dataCount = mDb.rawQuery("select id from " + DATABASE_JOURNAL_TABLE, null);
dataCount.getCount();

有关详细信息,请参见机器人devloper的文档的光标

See android devloper's doc for Cursor for more information.

这篇关于SQLite的计算范例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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