The following example illustrates how to create a service and then gives several examples of connecting to that service using different client methods.
In this example the service is enabled for run-time load balancing, as follows:
Service Name: HR.example.com
Running on database named CRM
The system consists of 4 nodes
Specifying SERVICE_TIME
as the value for the -rlbgoal
parameter
SCAN address of the listener is rws3010104-scan.example.com
Listener port is 1585
The service has a cardinality of two, but if needed, can be offered by any of the CRM database instances. The service configuration is as follows:
Preferred Instances: CRM1, CRM2
Available Instances: CRM3, CRM4
Specifying SHORT
as the value for the -clbgoal
parameter
The application using this service takes advantage of Application Continuity, so you must set -failovertype
and -commit_outcome
. Use the default retention parameters, but set a 10 second delay between connection attempts, and up to 40 retries before failing to get a connection.
Creating the HR Service Using SRVCTL
Create the HR service using SRVCTL, as follows:
$ srvctl add service –db CRM –service HR.example.com –preferred CRM1,CRM2 –available CRM3,CRM4 –clbgoal SHORT –failovertype TRANSACTION –commit_outcome TRUE –failoverdelay 10 –failoverretry 40
Start the HR.example.com
service, as follows:
$ srvctl start service –db CRM –service HR.example.com
The service is now be available on up to two instances, and CRM1 and CRM2 are the preferred instances.
Connecting to the HR Service from a JDBC Application
The application that connects to the HR service, in this example, is a JDBC application using the JDBC Universal Connection Pool with the JDBC thin driver.
In this example, a URL is constructed specifying the thin-style service name format for the database specifier. Fast Connection Failover is enabled, and remote Oracle Notification Service is configured, where the Oracle Notification Service daemon on the cluster listens on port 6200.
//import packages and register the driver import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import oracle.ucp.jdbc.PoolDataSourceFactory; import oracle.ucp.jdbc.PoolDataSource; PoolDataSource pds = PoolDataSourceFactory.getPoolDataSource(); //set the connection properties on the data source. pds.setConnectionPoolName("FCFPool"); pds.setFastConnectionFailoverEnabled(true); pds.setONSConfiguration("nodes=rws3010104-scan.example.com:6200"); pds.setConnectionFactoryClassName("oracle.jdbc.pool.OracleDataSource"); pds.setURL("jdbc:oracle:thin:@//rws3010104-scan.example.com:1585/HR.example.com"); pds.setUser("HR"); pds.setPassword("hr"); //Override any pool properties. pds.setInitialPoolSize(5); //Get a database connection from the datasource. Connection conn = pds.getConnection(); // do some work //return connection to pool conn.close(); conn=null
See Also:
Oracle Universal Connection Pool for JDBC Developer's Guide for more information about using Universal Connection Pool for JDBC