Java 使用 UnboundID LDAP SDK 的问题(带参数的调用方法)api
Java question (calling methods with parameters) using UnboundID LDAP SDK api
我正在为我的 LDAP 服务器使用 UnboundID LDAP SDK。
我做了一个连接方法。
public static LDAPConnection connectSDK(String ip, Integer port, String id, String pw) throws LDAPException {
LDAPConnection ldap = new LDAPConnection(ip,port,id,pw);
System.out.println("success");
return ldap;
}
在我的main方法中,我用参数调用了这个方法,它工作正常。
public static void main(String[] args) throws LDAPException {
connectSDK("192.168.0.60",389,"******","*****");
}
我想走得更远。我制作了一种使用过滤器搜索数据的方法。
public static void searchSDK(String filter) throws LDAPException {
LDAPConnection ldap = connectSDK();
/* Before calling a method with parameter, I used to connect with this,
and use 'ldap' variable to put search results.
Now, I am using a method with parameters.
I don't know what to do with 'ldap' variable.
If I delete it, 'SearchRequest' doesn't run.
Also how can I continue to use the connection from connectSDK method? */
SearchRequest searchRequest = new SearchRequest("c=kr",SearchScope.SUB,filter);
SearchResult searchResult = ldap.search(searchRequest);
System.out.println(searchResult);
}
最终,我想在我的 main 中调用其中两个方法,如下所示。
public static void main(String[] args) throws LDAPException {
//connect
connectSDK("192.168.0.60",389,"*****","******");
//search using a filter
searchSDK("hotdog");
}
我需要有关 searchSDK() 方法的建议。
*1) 如何使用创建的会话connectSDK方法
*2) 如何处理 'ldap' 变量。
*3) ldap.close() 我想在之后关闭一个会话,但是这个方法行不通。还有其他办法吗?
你的代码中没有这样的方法 LDAPConnection ldap = connectSDK();
As connectSDK(String ip, Integer port, String id, String pw)
returns a LDAPConnection
then pass this as a parameter into searchSDK
and remove connectSDK()
从中。
修改代码为
public static void searchSDK(String filter, LDAPConnection ldap) throws LDAPException {
// LDAPConnection ldap = connectSDK();
....
}
所以你的主要看起来像
LDAPConnection ldap = connectSDK("192.168.0.60",389,"*****","******");
//search using a filter
searchSDK("hotdog", ldap);
我正在为我的 LDAP 服务器使用 UnboundID LDAP SDK。 我做了一个连接方法。
public static LDAPConnection connectSDK(String ip, Integer port, String id, String pw) throws LDAPException {
LDAPConnection ldap = new LDAPConnection(ip,port,id,pw);
System.out.println("success");
return ldap;
}
在我的main方法中,我用参数调用了这个方法,它工作正常。
public static void main(String[] args) throws LDAPException {
connectSDK("192.168.0.60",389,"******","*****");
}
我想走得更远。我制作了一种使用过滤器搜索数据的方法。
public static void searchSDK(String filter) throws LDAPException {
LDAPConnection ldap = connectSDK();
/* Before calling a method with parameter, I used to connect with this,
and use 'ldap' variable to put search results.
Now, I am using a method with parameters.
I don't know what to do with 'ldap' variable.
If I delete it, 'SearchRequest' doesn't run.
Also how can I continue to use the connection from connectSDK method? */
SearchRequest searchRequest = new SearchRequest("c=kr",SearchScope.SUB,filter);
SearchResult searchResult = ldap.search(searchRequest);
System.out.println(searchResult);
}
最终,我想在我的 main 中调用其中两个方法,如下所示。
public static void main(String[] args) throws LDAPException {
//connect
connectSDK("192.168.0.60",389,"*****","******");
//search using a filter
searchSDK("hotdog");
}
我需要有关 searchSDK() 方法的建议。
*1) 如何使用创建的会话connectSDK方法
*2) 如何处理 'ldap' 变量。
*3) ldap.close() 我想在之后关闭一个会话,但是这个方法行不通。还有其他办法吗?
你的代码中没有这样的方法 LDAPConnection ldap = connectSDK();
As connectSDK(String ip, Integer port, String id, String pw)
returns a LDAPConnection
then pass this as a parameter into searchSDK
and remove connectSDK()
从中。
修改代码为
public static void searchSDK(String filter, LDAPConnection ldap) throws LDAPException {
// LDAPConnection ldap = connectSDK();
....
}
所以你的主要看起来像
LDAPConnection ldap = connectSDK("192.168.0.60",389,"*****","******");
//search using a filter
searchSDK("hotdog", ldap);