Previous Topic: Enabling Database Connection PoolingNext Topic: IBM WebSphere


Apache Tomcat

This section provides the steps to enable Apache Tomcat for JNDI-based database operations. To create a JNDI connection in Apache Tomcat:

  1. Install the Apache Tomcat application server and test the installation by using the following URL:

    http://localhost:8080/

  2. Open the server.xml file present in the <TOMCAT_HOME>/conf/ directory.
  3. Collect the following information for defining a data source:
  4. Add the following entry to define the data source within the <GlobalNamingResources> tag:
    <Resource name="SampleDS"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
            username="<userid>"
            password="<password>"
            driverClassName="<JDBC driver class>"
            url="<jdbc-url>"
            maxWait="30000"
            maxActive="32"
            maxIdle="8"
            initialSize="4"
            timeBetweenEvictionRunsMillis="300000"
            minEvictableIdleTimeMillis="30000"/>
    
  5. Open the context.xml file available in the <TOMCAT_HOME>/conf/ directory.
  6. Add the following entry to define the datasource within the <Context> tag:
    <ResourceLink global="SampleDS" name="SampleDS" type="javax.sql.DataSource"/>
    
  7. To enable database connection pooling, download the following files from the corresponding third-party source. Then, copy these files to <TOMCAT_HOME>/common/lib (on Apache Tomcat 5.x) or <TOMCAT_HOME>/lib (on Apache Tomcat 6.x and 7.x).

Configuration changes for Tomcat8 (apache-tomcat-8.0.24) and JDK8 (1.8.0_51)

  1. Creating JNDI connection:

    There are few configuration attribute names that have been updated in tomcat 8. Couple of them are listed in the sample here. Verify your attribute names from tomcat 8 documentation if you are using any others which are not shown in the sample.

    <Resource name="< data source_name >" auth="Container"

    type="javax.sql.DataSource" username="USER_ID" password="PASSWORD"

    driverClassName="JDBC_Driver_Class " url="JDBC_url" maxWaitMillis="30000"

    maxTotal="32" maxIdle="4" initialSize="4"

    timeBetweenEvictionRunsMillis="600000"

    minEvictableIdleTimeMillis="600000"/>

    Note :

    The maxActive configuration option has been renamed to maxTotal

    The maxWait configuration option has been renamed to maxWaitMillis

  2. Make sure you use the latest database jar.
  3. Enabling SSLv3

    Java 8 disables SSLv3 by default. To enable it follow these steps:

    1. Go to “<JRE_HOME>\lib\security” folder used by tomcat.
    2. Open java.security file.
    3. Check if the property “jdk.tls.disabledAlgorithms” has SSLv3, if yes remove the SSLv3 value.