Question & Answer
Question
How can I configure the DB2 JCC properties for DB2 pureScale affinity on Tomcat ?
Answer
For Java applications including stand alone or web applications in the Web Application Server (WAS), the necessary DB2 JDBC properties for DB2 pureScale affinity configuration are same.
For the detail of the JDBC properties, refer to the link in this page below.
Following steps are an example configuration of the client affinity on Tomcat.
1. Set pureScale member host names to the /etc/hosts of the operating system where Tomcat will be running.
As pureScale java client refers the serverlist which is received from pureScale server,
it's necessary to set the hosts and the pureScale member IP to the /etc/hosts file.
$ cat /etc/hosts ..... ### example ### pureScale client 192.168.153.65 db2ps1.au.ibm.com db2ps1 ### pureScale server 192.168.153.64 db2ps2.au.ibm.com db2ps2 # pureScale member 0 192.168.153.68 db2ps3.au.ibm.com db2ps3 # pureScale member 1 |
2. Add JNDI resource information to the web application environment file <TOMCAT_HOME>/conf/web.xml.
........ <!-- add from this line--> <resource-ref> <res-ref-name>jdbc/sample</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> <!-- to this line --> </web-app> |
3. Add JNDI data source information to tomcat configuration file <TOMCAT_HOME>/conf/context.xml
tomcat@db2ps1:~/tomcat7054/conf> cat context.xml <?xml version='1.0' encoding='utf-8'?> <Context> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- added following from this lines --> <Resource auth="Container" driverClassName="com.ibm.db2.jcc.DB2Driver" name="jdbc/sample" password="psinst2" username="psinst2" type="javax.sql.DataSource" url="jdbc:db2://db2ps3.au.ibm.com:61118/sample" enableClientAffinitiesList="1" retryIntervalForClientReroute="2" affinityFailbackInterval="300" user="psinst2" enableSeamlessFailover="true" clientRerouteAlternateServerName="db2ps3.au.ibm.com,db2ps2.au.ibm.com" databaseName="sample" maxRetriesForClientReroute="3" clientRerouteAlternatePortNumber="61118,61118" driverType="4" currentSchema="psinst2" removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true" /> <!-- to this lines --> </Context> |
4. Sample application code to get connection from the datasource name.
..... Connection conn = null; Statement stmt = null; ResultSet rs = null; try { Context c = new InitialContext(); DataSource ds =(DataSource)c.lookup("java:comp/env/jdbc/sample"); conn = ds.getConnection(); ...... |
5. During client affinity test, following message will be recorded in the Tomcat log file <TOMCAT_HOME>/logs/catalina.out
com.ibm.db2.jcc.am.ClientRerouteException: [jcc][t4][2027][11212][3.63.123] A connection failed but has been re-established. The host name or IP address is "db2ps2.au.ibm.com" and the service name or port number is 61,118. |
Related Information
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21677882