Tutorial :JNDI Obtain the size of a LDAP search without retrieving all the data


I need to know how many users and groups are in my LDAP directory. The search looks fairly simple:

(| (objectClass=group)(objectClass=user))

The problem is that the API is very limited. I can only get a NamingEnumeration<SearchResult> and it doesn't have a count. I didn't find any functions we can use, like the count in SQL.

Is there any way I can get this count without having to retrieve the full query and count the results with a loop?


The only way I found to do this was to make a query for an empty attribute array, then loop and increment a counter.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »