The following Java code example creates a DataDirect Connect Series for JDBC driver DataSource object and registers it with a JNDI naming service.
The DataSource class is provided by DataDirect Connect Series for JDBC and is database-dependent. In this example we use Oracle, so the DataSource class is OracleDataSource. Refer to the appropriate driver chapter in the
DataDirect Connect Series for JDBC User’s Guide for the name of the DataSource class for your driver.
// This code creates a DataDirect Connect Series for JDBC data source and
// registers it to a JNDI naming service. This JDBC data source uses the
// DataSource implementation provided by DataDirect Connect Series
public static void main(String argv[])
// Set up data source reference data for naming context:
// ----------------------------------------------------
// Create a class instance that implements the interface
// ConnectionPoolDataSource
OracleDataSource ds = new OracleDataSource();
ds.setDescription("Oracle on Sparky - Oracle Data Source");
ds.setServerName("sparky");
// Set up environment for creating initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:c:\\JDBCDataSource");
Context ctx = new InitialContext(env);
// Register the data source to JNDI naming service
ctx.bind("jdbc/ConnectSparkyOracle", ds);
// class OracleDataSourceRegisterJNDI
To create a connection pool, you must create and register with JNDI a PooledConnectionDataSource object. The following Java code creates a PooledConnectionDataSource object and registers it with a JNDI naming service.
To specify the driver DataSource object to be used by the connection pool to create pooled connections, set the parameter of the DataSourceName method to the JNDI name of a registered driver DataSource object. For example, the following code sets the parameter of the DataSourceName method to the JNDI name of the driver DataSource object created in
“Creating a Driver DataSource Object”.
public static void main(String argv[])
// Set up data source reference data for naming context:
// ----------------------------------------------------
// Create a pooling manager's class instance that implements
// the interface DataSource
PooledConnectionDataSource ds = new PooledConnectionDataSource();
ds.setDescription("Sparky Oracle - Oracle Data Source");
// Specify a registered driver DataSource object to be used
// by this data source to create pooled connections
ds.setDataSourceName("jdbc/ConnectSparkyOracle");
// The pool manager will be initiated with 5 physical connections
ds.setInitialPoolSize(5);
// The pool maintenance thread will make sure that there are 5
// physical connections available
// The pool maintenance thread will check that there are no more
// than 10 physical connections available
// The pool maintenance thread will wake up and check the pool
// The pool maintenance thread will remove physical connections
// that are inactive for more than 300 seconds
// Set tracing off because we choose not to see an output listing
// of activities on a connection
// Set up environment for creating initial context
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:c:\\JDBCDataSource");
Context ctx = new InitialContext(env);
// Register this data source to the JNDI naming service
ctx.bind("jdbc/SparkyOracle", ds);