该死的1000条限制....
我用的novell的jar包连接的LDAP。可总是查询到1000的时候报错,代码这样写的。坛子里有人遇见过,解决了也没说清怎么解决,现在我把代码贴上来,谁能帮我看看,我用的IBM的LDAP,novell的jar。
[quote]
import com.novell.ldap.*;
import java.util.*;
public class test_del{
@SuppressWarnings("deprecation")
public static void main(String args[]){
try{
LDAPConnection lc = new LDAPConnection();
lc.connect("192.168.0.26",389);
lc.bind(LDAPConnection.LDAP_V3,"cn=root","db2admin");
System.out.println("asdf");
LDAPSearchResults lrs = lc.search("cn=users,dc=yourco,dc=com",LDAPConnection.SCOPE_SUB,"objectclass=*",null,true);
ArrayList<String> list = new ArrayList<String>();
int a = 0;
while(lrs.hasMore()){
System.out.println(" "+a);
LDAPEntry entry = lrs.next();
a++;
System.out.println(a);
String DN = entry.getDN();
System.out.println(DN);
}
for(int i=list.size()-1;i>=0;i--){
if(!((String)list.get(i)).equals("dc=zhengxin,dc=com")){
lc.delete((String)list.get(i));
}else{
System.out.println("警告:根目录不可删除...");
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}
[/quote]
听说要有个参数设置,在那呢?
[[i] 本帖最后由 chen_bo 于 2007-8-28 14:10 编辑 [/i]] ldap的“搜索返回条目书限制“包括两个方面:服务器端,客户端。
服务器端限制:
对于Tivoli Directory来说,就是通过ibm-slapdSizeLimit参数是设置。
客户端限制:
对你们目前的问题而言就是以下语句中的默认Sizelimit是1000.
LDAPConnection lc = new LDAPConnection();
LDAPSearchResults lrs = lc.search("cn=users,dc=yourco,dc=com",LDAPConnection.SCOPE_SUB,"objectclass=*",null,true);
参考以下 novell文档,其中有具体描述.
=================================================
1.[url]http://developer.novell.com/documentation/jldap/jldapenu/api/com/novell/ldap/LDAPConnection.html[/url]
LDAPSearchResults search(java.lang.String base, int scope, java.lang.String filter, java.lang.String[] attrs, boolean typesOnly, LDAPSearchConstraints cons)
Synchronously performs the search specified by the parameters, using the specified search constraints (such as the maximum number of entries to find or the maximum time to wait for search results).
=================================================
2.[url]http://developer.novell.com/documentation/jldap/jldapenu/api/com/novell/ldap/LDAPSearchConstraints.html#getMaxResults[/url]()
getMaxResults
public int getMaxResults()Returns the maximum number of search results to be returned for a search operation. A value of 0 means no limit. Default: 1000 The search operation will be terminated with an LDAPException.SIZE_LIMIT_EXCEEDED if the number of results exceed the maximum.
Returns:
The value for the maximum number of results to return.
See Also:
setMaxResults(int), LDAPException.SIZE_LIMIT_EXCEEDED
=================================================
所以,你可以尝试加入此句.
LDAPConnection lc = new LDAPConnection();
[color=Red]lc.setMaxResults(100000); // [/color]
LDAPSearchResults lrs = lc.search("cn=users,dc=yourco,dc=com",LDAPConnection.SCOPE_SUB,"objectclass=*",null,true);
回复 #2 prattle 的帖子
嗯。lc.setMaxResults(0);
这样就没有限制了。
页:
[1]