Specifying Primary and Alternate Servers
- Last Updated: May 15, 2020
- 2 minute read
- DataDirect Connectors
- JDBC
- IBM Db2 5.1
- MySQL 5.1
- Progress OpenEdge 5.1
- SAP Sybase 5.1
- Documentation
Connection information for primary and alternate servers can be specified using either one of the following methods:
- Connection URL through the JDBC Driver Manager
- JDBC data source
For example, the following connection URL for the DB2 driver specifies connection information for primary and alternate servers using a connection URL:
jdbc:datadirect:db2://server1:50000;DatabaseName=TEST;User=test;
Password=secret;AlternateServers=(server2:50000;DatabaseName=TEST2,
server3:50000;DatabaseName=TEST3)
In this example:
...server1:50000;DatabaseName=TEST...
is the part of the connection URL that specifies connection information for the primary server. Alternate servers are specified using the AlternateServers property. For example:
...;AlternateServers=(server2:50000;DatabaseName=TEST2,server3:50000;
DatabaseName=TEST3)
Similarly, the same connection information for primary and alternate servers specified using a JDBC data source would look like this:
DB2DataSource mds = new DB2DataSource();
mds.setDescription("My DB2DataSource");
mds.setServerName("server1");
mds.setPortNumber(50000);
mds.setDatabaseName("TEST");
mds.setUser("test");
mds.setPassword("secret");
mds.setAlternateServers("server2:50000;DatabaseName=TEST2,server3:50000;
DatabaseName=TEST3")
In this example, connection information for the primary server is specified using the ServerName, PortNumber, and DatabaseName properties. Connection information for the alternate servers is specified using the AlternateServers property.
The value of the AlternateServers property is a string that has the format:
(servername1[:port1][;property=value[;...]][,servername2[:port2]
[;property=value[;...]]]...)
where:
servername1- is the IP address or server name of the first alternate
database server,
servername2is the IP address or server name of the second alternate database server, and so on. The IP address or server name is required for each alternate server entry. - port1
- is the port number on which the first alternate database server is
listening, port2 is the port number on which the second alternate
database server is listening, and so on. Port numbers are optional for each alternate server
entry. If unspecified, the port number specified for the primary server is used. If a port
number is unspecified for the primary server, a default port number of
50000is used. - property
=value - is one of the following connection properties: DatabaseName or LocationName. These connection properties are optional for each alternate server entry. For example:
jdbc:datadirect:db2://server1:50000;DatabaseName=TEST;User=test;
Password=secret;AlternateServers=(server2:50000;DatabaseName=TEST2,
server3:50000;DatabaseName=TEST2)
or
jdbc:datadirect:db2://server1:50000;LocationName=TEST;User=test;
Password=secret;AlternateServers=(server2:50000;LocationName=TEST2,
server3:50000;LocationName=TEST3)
If you do not specify an optional connection property in an alternate server entry, the
connection to that alternate server uses the property specified in the URL for the primary
server. For example, if you specify DatabaseName=TEST for the primary
server, but do not specify a database name in the alternate server entry as shown in the
following URL, the driver uses the database name specified for the primary server and tries
to connect to the TEST database on the alternate server:
jdbc:datadirect:db2://server1:50000;DatabaseName=TEST;User=test;
Password=secret;AlternateServers=(server2:50000,server3:50000)