Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LdapContext, how to do select count(*)

Tags:

java

ldap

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.

like image 948
Yoni Avatar asked Nov 06 '22 22:11

Yoni


2 Answers

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.

like image 121
geoffc Avatar answered Nov 12 '22 15:11

geoffc


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

like image 32
kgiannakakis Avatar answered Nov 12 '22 17:11

kgiannakakis