code: public static int count(Connection connection, String sql,
  			String[] selectionArgs) {
  
  		if (!sql.toLowerCase().contains(" count(*) ")) {
  			int index = sql.toLowerCase().indexOf(" from ");
  			if (index == -1) {
  				return -1;
  			}
  			sql = "select count(*)" + sql.substring(index);
  		}
  
  		int count = querySingleInteger(connection, sql, selectionArgs, true);
  
  		return count;
  	}
docs: Attempt to count the results of the query
  
  @param connection
  connection
  @param sql
  sql statement
  @param selectionArgs
  selection arguments
  @return count if known, -1 if not able to determine