title: connection refused error with LDAP?
body: <p>I am trying to run following program: </p>
  
  <pre><code>package jndi;
  
  import java.util.Hashtable;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.naming.directory.Attributes;
  import javax.naming.directory.DirContext;
  
  
  public class LDAPRead {
  
      public static void main(String[] args) {
  
          Hashtable env = new Hashtable();
          env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
          env.put(Context.PROVIDER_URL, "ldap://localhost:389/o=jaydeetechnology");
          try{
              System.out.println("creating initial directory context");
              DirContext ctx = (DirContext) new InitialContext(env);
              System.out.println("search for john hunt");
              Attributes attrs = ctx.getAttributes("cn=John Hunt , ou=JayDeeTechnology");
              System.out.println("find the surname and print it");
              System.out.println("sn: "+attrs.get("sn").get());
              ctx.close();
          }catch(NamingException e){
              e.printStackTrace();
          }
      }
  
  }
  </code></pre>
  
  <p>but I am getting 'Connection refused' error. Could any one please help me if I am missing something?</p>
  
  <pre><code>creating initial directory context
  javax.naming.CommunicationException: localhost:389 [Root exception is java.net.ConnectException: Connection refused: connect]
      at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:222)
      at com.sun.jndi.ldap.LdapClient.&lt;init&gt;(LdapClient.java:130)
      at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1592)
      at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2664)
      at com.sun.jndi.ldap.LdapCtx.&lt;init&gt;(LdapCtx.java:305)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:187)
      at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:205)
      at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:148)
      at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:78)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:235)
      at javax.naming.InitialContext.initializeDefaultInitCtx(InitialContext.java:318)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:348)
      at javax.naming.InitialContext.internalInit(InitialContext.java:286)
      at javax.naming.InitialContext.&lt;init&gt;(InitialContext.java:211)
      at jndi.LDAPRead.main(LDAPRead.java:31)
  Caused by: java.net.ConnectException: Connection refused: connect
      at java.net.PlainSocketImpl.socketConnect(Native Method)
      at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:383)
      at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:245)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:232)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
      at java.net.Socket.connect(Socket.java:539)
      at java.net.Socket.connect(Socket.java:488)
      at java.net.Socket.&lt;init&gt;(Socket.java:385)
      at java.net.Socket.&lt;init&gt;(Socket.java:199)
      at com.sun.jndi.ldap.Connection.createSocket(Connection.java:364)
      at com.sun.jndi.ldap.Connection.&lt;init&gt;(Connection.java:199)
      ... 14 more
  </code></pre>
  
  <p>I am using RSA 8.0</p>