SQLite的计算范例范例、SQLite

由网友(让时间说真话づ)分享简介:我使用的SQLite在Android中。我有查询,查询执行以及如何从光标打印计数。I am using SQLite in Android.I have the query, query executed and how to print count from cursor.Cursor dataCount =...

我使用的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.

阅读全文

相关推荐

最新文章