How to use the ORMLite query builder to get the to

2019-04-03 07:00发布

Similar to

select count(*) from tablename;

what should be query in ORMLITE

i tried something like

int total = dao.queryBuilder().("select count(*)");

2条回答
爷、活的狠高调
2楼-- · 2019-04-03 07:11

How to use the ORMLite query builder to get the total records in a table

ORMLite has a Dao.countOf() method that returns the total number of rows in a table:

long numRows = dao.countOf();

You can also count the number of rows in a custom query by calling the countOf() method on the Where or QueryBuilder object.

// count the number of lines in this custom query
long numRows = dao.queryBuilder().where().eq("name", "Joe Smith").countOf();
查看更多
Deceive 欺骗
3楼-- · 2019-04-03 07:18

for package 5: you can use countOf()

From the docs:

Returns the value returned from a SELECT COUNT(*) query which is the number of rows in the table. Depending on the database and the size of the table, this could be expensive.

查看更多
登录 后发表回答