skip to main content
Quick Start: Accessing REST data sources using HTTP header authentication : Connecting to a DataSource : Connecting using data sources : Calling a data source in an application
  

Try DataDirect Drivers Now
Calling a data source in an application
Applications can call a Progress DataDirect data source using a logical name to retrieve the javax.sql.DataSource object. This object loads the specified driver and can be used to establish a connection to the database.
Once the data source has been registered with JNDI, it can be used by your JDBC application as shown in the following code example.
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("EmployeeDB");
Connection con = ds.getConnection("domino", "spark");
In this example, the JNDI environment is first initialized. Next, the initial naming context is used to find the logical name of the data source (EmployeeDB). The Context.lookup() method returns a reference to a Java object, which is narrowed to a javax.sql.DataSource object. Then, the DataSource.getConnection() method is called to establish a connection.