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);