Database Reference
In-Depth Information
Our test code for UCP is in a separate file,
OraSSOTests2.java
. When you compile and run this code,
you will need to include the
ucp.jar
file in your
CLASSPATH
, as shown in Listing 8-18.
Listing 8-18.
Command to Compile and Run with UCP.jar
javac -classpath "%CLASSPATH%";ucp.jar OraSSOTests2.java
java -classpath "%CLASSPATH%";ucp.jar OraSSOTests2
A better approach, if you are going to use UCP, would be to add it to your
CLASSPATH
in the OS
environment, as described in Chapter 3.
Use a Connection Pool Factory
UCP uses a
PoolDataSourceFactory
class to instantiate the pool connections. We provide the
PoolDataSource
with the fully-qualified name of the class to be used for each connection,
“oracle.jdbc.pool.OracleDataSource,” and we set the URL (connection string) to be used for the
connections. See Listing 8-19.
Listing 8-19.
Configure UCP Connection Pool
private String appusrConnString =
"jdbc:oracle:
thin
:appusr/password@localhost:1521:orcl";
PoolDataSource cpool = PoolDataSourceFactory.getPoolDataSource();
cpool.
setConnectionFactoryClassName
("oracle.jdbc.pool.OracleDataSource");
cpool.
setURL
( appusrConnString );
cpool.setInitialPoolSize(5);
cpool.setMinPoolSize(2);
cpool.setMaxPoolSize(10);
We call methods of the
PoolDataSource
class,
cpool
to set some properties of the connection pool.
Note That UCP Is a Thin Client Implementation
Notice that the URL we specify (above) is a lightweight, thin connection. We are also able to specify the
URL in the straightforward connection string syntax, as shown in Listing 8-20. If desired, we could
specify the URL in TNSNames format and provide the user and password in separate method calls. We
can also specify the straightforward connection string syntax, leaving out the user and password, and
provide user and password in separate method calls.