Be familiar with the JNDI specification to use SAP jConnect with JNDI.
See the JNDI specification from Oracle Technology Network.
In particular, make sure that required initialization properties are set in javax.naming.directory.DirContext when JNDI and SAP jConnect are used together. Set these properties either at the system level or at runtime.
Context.INITIAL_CONTEXT_FACTORY – takes the fully qualified class name of the initial context factory for JNDI to use. This determines the JNDI driver that is used with the URL specified in the Context.PROVIDER_URL property.
Context.PROVIDER_URL – takes the URL of the directory service that the driver (for example, the LDAP driver) is to access. The URL should be a string, such as “ldap://ldaphost:427”.
Properties props = new Properties(); /* We want to use LDAP, so INITIAL_CONTEXT_FACTORY is set to the * class name of an LDAP context factory. In this case, the * context factory is provided by Sun’s implementation of a * driver for LDAP directory service. */ props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); /* Now, we set PROVIDER_URL to the URL of the LDAP server that * is to provide directory information for the connection. */ props.put(Context.PROVIDER_URL, "ldap://ldap_server1:389"); /* Set up additional context properties, as needed. */ props.put("user", "xyz"); props.put("password", "123"); /* get the connection */ Connection con = DriverManager.getConnection ("jdbc:sybase:jndi:ldap://ldap_server1:389" + "/servername=Sybase11,o=MyCompany,c=US",props);
The connection string passed to getConnection contains LDAP-specific information, which the developer must provide.
javax.naming.directory.DirContext ctx = new javax.naming.directory.InitialDirContext(props);
javax.naming.directory.Attributes attrs = ctx.getAttributes("ldap://ldap_server1:389/servername=" + "Sybase11", SYBASE_SERVER_ATTRIBUTES);
SYBASE_SERVER_ATTRIBUTES is an array of strings defined within SAP jConnect. The array values are the OIDs for the required directory information listed in Required Directory Service Information.