skip to main content
Configuring Hybrid Data Pipeline for JDBC : Using connection pooling : Connecting to a JDBC Data Source using a connection pool
  

Try Now

Connecting to a JDBC Data Source using a connection pool

Once a connection pool has been created and registered with JNDI, it can be used by your JDBC application when it creates the connection to the JDBC data source as shown in the following code snippet, typically through a third-party connection pool tool:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/PoolHybridSparky");
Connection conn = ds.getConnection("DDusername", "DDpassword");
In this example, first, the JNDI environment is initialized. Next, the initial naming context is used to find the data source associated with the connection pool defined in the previous section using the logical name of that pool (jdbc/PoolHybridSparky). The Context.lookup method returns a reference to a Java object, which is narrowed to a javax.sql.PoolDataSource object. Next, the PoolDataSource.getConnection() method is called to establish a connection with the JDBC data source.
* Closing the DataDirect connection pool
* Complete example of using a connection pool