Ibm Data Server Driver For Jdbc And Sqlj Client Reroute Support With Jndi - IBM DB2 Manual

Table of Contents

Advertisement

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IBM Data Server Driver for JDBC and SQLJ client reroute
support with JNDI
The following code sets up DataSource properties in an application so that the
application connects to cm2.sf.ibm.com as the main Connection Manager, and
cm1.sf.ibm.com as the alternative Connection Manager. That is, if cm2.sf.ibm.com is
down during the initial connection, the driver should connect to cm1.sf.ibm.com.
ds.setDriverType(4);
ds.setServerName("cm2.sf.ibm.com");
ds.setPortNumber("50002");
ds.setClientRerouteAlternateServerName("cm1.sf.ibm.com");
ds.setClientRerouteAlternatePortNumber("50000");
The following code configures JNDI for client reroute. It creates an instance of
DB2ClientRerouteServerList, binds that instance to the JNDI registry, and assigns
the JNDI name of the DB2ClientRerouteServerList object to the
clientRerouteServerListJNDIName property.
// Create a starting context for naming operations
InitialContext registry = new InitialContext();
// Create a DB2ClientRerouteServerList object
DB2ClientRerouteServerList address = new DB2ClientRerouteServerList();
// Set the port number and server name for the main Configuration Manager
address.setPrimaryPortNumber(50002);
address.setPrimaryServerName("cm2.sf.ibm.com");
// Set the port number and server name for the alternative Configuration Manager
int[] port = {50000};
String[] server = {"cm1.sf.ibm.com"};
address.setAlternatePortNumber(port);
address.setAlternateServerName(server);
registry.rebind("serverList", address);
// Assign the JNDI name of the DB2ClientRerouteServerList object to the
// clientRerouteServerListJNDIName property
datasource.setClientRerouteServerListJNDIName("serverList");
If you make connections with the javax.sql.DataSource,
javax.sql.ConnectionPoolDataSource, or javax.sql.XADataSource interface, you
indicate to the IBM Data Server Driver for JDBC and SQLJ that JNDI is configured
for client reroute by setting the clientRerouteServerListJNDIName property.
You can also specify the clientRerouteServerListJNDIContext property, which
provides the JNDI context that is used for binding and lookup of a
DB2ClientRerouteServerList instance.
For client reroute with JNDI, the in-memory primary and alternate server
information is an instance of the DB2ClientRerouteServerList class, which
implements the javax.naming.Referenceable interface.
DB2ClientRerouteServerList is a serializable Java bean with the following
properties:
Property name
com.ibm.db2.jcc.DB2ClientRerouteServerList.alternateServerName
com.ibm.db2.jcc.DB2ClientRerouteServerList.alternatePortNumber
com.ibm.db2.jcc.DB2ClientRerouteServerList.primaryServerName
com.ibm.db2.jcc.DB2ClientRerouteServerList.primaryPortNumber
Chapter 3. JDBC application programming
Data type
String[]
int[]
String[]
int[]
89

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents