Powered by Zoomin Software. For more details please contactZoomin

DataDirect OpenAccess SDK Help

Using JNDI for Naming Databases

  • Last Updated: May 12, 2026
  • 1 minute read
    • OpenAccess SDK
    • Version 8.1
    • Documentation

Instead of using connection URLs, client applications can access a JNDI-named data source using a logical name to retrieve the javax.sql.DataSource object. This object loads the driver and establishes the connection to the service.

Once a JDBC data source has been registered with JNDI, it can be used by your JDBC application as shown in the following example:

Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/EmployeeDB");
Connection con = ds.getConnection("john", "be4ch");

In this example, the JNDI environment is first initialized. Next, the initial naming context is used to find the logical name of the JDBC data source. The Context.lookup() method returns a reference to a Java object, which is narrowed to a javax.sql.DataSource object. Finally, the DataSource.getConnection() method is called to establish a connection with the service.

See Creating and Managing JDBC Data Sources for instructions on creating JDBC data sources.

TitleResults for “How to create a CRG?”Also Available inAlert