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

纵饮孤独 提交于 2019-12-05 09:33:45

问题


Similar to

select count(*) from tablename;

what should be query in ORMLITE

i tried something like

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

回答1:


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();



回答2:


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.



来源:https://stackoverflow.com/questions/12260781/how-to-use-the-ormlite-query-builder-to-get-the-total-records-in-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!