LookupUrl.java

 


/* 
 * LookupUrl.java
 */

import javax.naming.*;
import java.io.File;
import java.util.Hashtable;

/**
  * Demonstrates how to look up an object using an LDAP URL
  * from the InitialContext
  *
  * usage: java LookupUrl
  */
class LookupUrl 
{
    public static void main(String[] args) 
    {

	try 
        {
	    // Create the initial context
	    Context ctx = new InitialContext();

	    String url = "ldap://localhost:389/cn=homedir,cn=John Doe,ou=people,o=JNDIDocs";

	    // Perform lookup using URL
	    System.out.println(ctx.lookup(url));

	    // Close ctx when done
	    ctx.close();
	} 
        catch (NamingException e) 
        {
	    System.out.println("Lookup failed: " + e);
	}
    }
}