Data source configuration for Java when using an Apache Tomcat web server

A data source is a named connection to a database. You must specify a data source within the web application server to publish a feature service to ArcGIS Spatial Data Server for the Java platform. Typically, the data source object is configured with a naming service based on the Java Naming and Directory Interface (JNDI) API.

After you have installed and configured Tomcat, do the following to prepare it for use with ArcGIS Spatial Data Server:

Place the JDBC driver in the Tomcat home directory

You must place the JDBC driver for your DBMS in the lib directory of $CATALINA_HOME.

Alter the Tomcat context.xml file

If you use an Apache Tomcat web server, you must specify your data source in the default web configuration file—context.xml. To edit context.xml, do the following:

  1. Navigate to the conf directory in the Tomcat installation directory.
  2. Make a backup copy of the context.xml file.
  3. Open the context.xml file in a text editor.
  4. Alter the information in the <Resource name> element to work for your site. (Examples are provided in this topic.) The <Resource name> element is nested inside the <Context> element.

    There can be other elements inside the <Context> element, but be sure the <Resource name> element is one level below the <Context> element and not nested inside one of the other elements.

  5. Save and close the context.xml file.
  6. Restart the Tomcat server.

If you do not add your data source to the context.xml file, or if you do not preface the <Resource name> element attribute with jdbc/, you will receive the following error message:

Name jdbc is not bound in this Context

Examples

The following are examples of configuring a data source in the Tomcat context.xml file for each of the supported databases. There are examples for two types of connection pools for each database: a database connection pool (DBCP) and a JDBC connection pool. The JDBC connection pool is recommended by Apache. See the Apache Tomcat documentation for more information and an explanation of possible attributes you can use in the <Resource name> element.

TipTip:

If you will be configuring multiple data sources, use data source names that reflect the properties of the data source. For example, you could include the server, database, and user names in the data source name. This will help you to identify the data sources without having to look up the properties in the web application server files or consoles.

PostgreSQL

The following is an example <Resource> element for PostgreSQL that uses a DBCP. The values denoted by Xs indicate information specific to your site that you will provide.

<Context>
    <Resource name="jdbc/X" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://X:X/X"
              username="X" 
              password="X" 
              maxActive="X" 
              maxIdle="X" 
              maxWait="X"/>
</Context>

In this example, the resource name is jdbc/pgservername, and the data source is a PostgreSQL database (pgdbname) listening on port 5432 on server pgservername.

<Context>
    <Resource name="jdbc/pgservername_pgdbname_pgusername" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="org.postgresql.Driver"
              url="jdbc:postgresql://pgservername:5432/pgdbname"
              username="pgusername" 
              password="pgpassword246" 
              maxActive="20" 
              maxIdle="10" 
              maxWait="-1"/>
</Context>

The next example is for the same PostgreSQL database, but uses a JDBC connection pool:

<Context>
     <Resource name="jdbc/pgservername_pgdbname_pgusername" 
               factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
               driverClassName="org.postgresql.Driver"
               url="jdbc:postgresql://pgservername:5432/pgdbname" 
               username="pgusername"
               password="pgpassword246"
               initialSize="20"
               maxActive="80" 
               maxIdle = "30" 
               minIdle="20"
               timeBetweenEvictionRunsMillis="30000"
               minEvictableIdleTimeMillis="60000"
               testOnBorrow="true"
               validationQuery="SELECT 1" 
               validationInterval="30000" 
               removeAbandoned="true"
               removeAbandonedTimeout="60" 
               logAbandoned="true" 
               abandonWhenPercentageFull="60"
               jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"/>
</Context>

Oracle

The following is an example <Resource> element for Oracle. The values denoted by Xs indicate information specific to your site that you will provide.

<Context>
    <Resource name="jdbc/X" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@X:X:X"
              username="X" 
              password="X" 
              maxActive="X" 
              maxIdle="X"
              maxWait="X"/>
</Context>

In this example, the resource name is jdbc/oraservername, and the data source is an Oracle database on server oraservername listening on database port 1521. The Oracle SID is osid. The Oracle SID must be configured prior to registering the data source.

<Context>
    <Resource name="jdbc/oraservername_osid_orausername" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="oracle.jdbc.OracleDriver"
              url="jdbc:oracle:thin:@oraservername:1521:osid"
              username="orausername" 
              password="0rapassword123" 
              maxActive="20" 
              maxIdle="10"
              maxWait="-1"/>
</Context>

The next example is for the same Oracle database, but uses a JDBC connection pool:

<Context>
    <Resource name="jdbc/oraservername_osid_orausername" 
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
              driverClassName="oracle.jdbc.driver.OracleDriver"
              url="jdbc:oracle:thin:@oraservername:1521:osid" 
              username="orausername"
              password="0rapassword123"
              initialSize="20"
              maxActive="80" 
              maxIdle = "30" 
              minIdle="20"
              timeBetweenEvictionRunsMillis="30000"
              minEvictableIdleTimeMillis="60000"
              testOnBorrow="true"
              validationQuery="SELECT 1 FROM DUAL" 
              validationInterval="30000" 
              removeAbandoned="true"
              removeAbandonedTimeout="60" 
              logAbandoned="true" 
              abandonWhenPercentageFull="60"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"/>
</Context>

DB2

The following is an example <Resource> element for DB2. The values denoted by Xs indicate information specific to your site that you will provide.

<Context>
    <Resource name="jdbc/X" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="com.ibm.db2.jcc.DB2Driver"
              url="jdbc:db2://X:X/X"
              username="X" 
              password="X" 
              maxActive="X" 
              maxIdle="X"
              maxWait="X"/>
</Context>

In this example, the resource name is jdbc/db2servername, the DB2 server is db2servername, the database port is 60000, and the cataloged database is db2dba.

<Context>
    <Resource name="jdbc/db2servername_db2dba_db2username" 
              auth="Container"
              type="javax.sql.DataSource" 
              driverClassName="com.ibm.db2.jcc.DB2Driver"
              url="jdbc:db2://db2servername:60000/db2dba"
              username="db2username" 
              password="db2password975" 
              maxActive="20" 
              maxIdle="10"
              maxWait="-1"/>
</Context>

The next example is for the same DB2 database, but uses a JDBC connection pool:

<Context>
    <Resource name="jdbc/db2servername_db2dba_db2username" 
              factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" 
              driverClassName="com.ibm.db2.jcc.DB2Driver"
              url="jdbc:db2://db2servername:60000/db2dba" 
              username="db2username"
              password="db2password975"
              initialSize="20"
              maxActive="80" 
              maxIdle = "30" 
              minIdle="20"
              timeBetweenEvictionRunsMillis="30000"
              minEvictableIdleTimeMillis="60000"
              testOnBorrow="true"
              validationQuery="VALUES 1" 
              validationInterval="30000" 
              removeAbandoned="true"
              removeAbandonedTimeout="60" 
              logAbandoned="true" 
              abandonWhenPercentageFull="60"
              jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer"/>
</Context>

Related Topics

8/21/2012