Yoni
Yoni

Reputation: 10321

LdapContext, how to do select count(*)

I am using an LdapContext in java to query an LDAP server (I think the server is Sun server version 5.2). I use the LdapContext.search(String name, String filter, SearchControls cons) method for the regular querys, but I don't know how to run a query equivalent to sql's "select count(*)". Any idea? Performance is important so I don't want to just run a regular query and count the results.

Upvotes: 5

Views: 2768

Answers (3)

meher ben ahmed
meher ben ahmed

Reputation: 21

you can't count directly the number of user from LDAP. You must for exemple bring all data you want to count into data structure in LIST and count it.

Upvotes: 0

geoffc
geoffc

Reputation: 4100

I do not believe there is an equivalent to the "select count(*)" function in SQL.

I think you will have to retrieve the results of your query into some data structure, and count the number of nodes in there.

To my knowledge there is nothing in the LDAP command set that allows this, therefore if you happened to find such a feature in an LDAP server you would have to test to see if it worked anywhere else, if you cared about cross server compatibility.

Upvotes: 1

kgiannakakis
kgiannakakis

Reputation: 104188

Have you tried the Context.list(String name) method? I don't know about the performance and you can't apply filters.

Upvotes: 1

Related Questions