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

Sourabh Saldi picture Sourabh Saldi · Sep 4, 2012 · Viewed 20.3k times · Source

Similar to

select count(*) from tablename;

what should be query in ORMLITE

i tried something like

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

Answer

Gray picture Gray · Sep 4, 2012

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