my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes How tp use SearchFilter with JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How tp use SearchFilter with JNDI" Watch "How tp use SearchFilter with JNDI" New topic
Author

How tp use SearchFilter with JNDI

raga menon
Greenhorn

Joined: May 08, 2007
Posts: 8
Hi all,

i have to search the entry and display the enties. here i used the search
filter for that, when i try to compile the program am getting the error.
ERROR:

Search.printSearchEnumeration(answer);
here

code:
--------------------------------------
import javax.naming.*;
import javax.naming.directory.*;

import java.util.Hashtable;

/**
* Demonstrates how to perform a search by specifying a search filter
* and default search controls. Functionally identical to SearchRetAll.java.
*
* usage: java SearchWithFilterRetAll
*/
class SearchWithFilter
{
public static void main(String[] args) {

// Set up the environment for creating the initial context
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://localhost:2389/dc=example,dc=com");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "cn=Directory Manager");
env.put(Context.SECURITY_CREDENTIALS, "secret");

try {
// Create initial context
DirContext ctx = new InitialDirContext(env);

// Create default search controls
SearchControls ctls = new SearchControls();

// Specify the search filter to match
// Ask for objects with attribute sn == Geisel and which have
// the "mail" attribute.
String filter = "(uid=user.10)";

// Search for objects using filter
NamingEnumeration answer = ctx.search("ou=People", filter, ctls);

// Print the answer
search.printSearchEnumeration(answer);

// Close the context when we're done
ctx.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
============================================

how could i achive this..

bye..
Raga
Oliver Kamps
Greenhorn

Joined: May 15, 2007
Posts: 18
Hi Raga,

code is much easier to read if you put it into code tags (see the buttons below the edit box).

You could have saved some time by providing the error message in your question. My compiler says:

"search cannot be resolved"

You have not declared the variable "search" anywhere in your code.

Hope this helps,
Oliver
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How tp use SearchFilter with JNDI