Working with JNDIΒΆ

Applications such as GeoServer are in position to work with database connection pools set up by the application server. The Java Naming and Directory Interface (JNDI) can be used to create a connection pool for a JDBC data source.

These instructions will set up a JNDI connection pool on the Tomcat application server using a PostgreSQL data source:

Note

Tomcat is the application server used in:

  • OpenGeo Suite for Ubuntu Linux
  • OpenGeo Suite for Red Hat-based Linux

Tomcat can also be used with:

  • OpenGeo Suite for Application Servers
  1. Copy the JDBC Driver for your database to <TOMCAT_HOME>/lib. The JDBC driver can often be found on the website of your DBMS provider, or in the installed version of your database.

    Note

    The PostgreSQL JDBC Driver can be found at the PostgreSQL web site or in the geoserver/WEB-INF/lib directory.

  2. Remove the JDBC Driver from the WEB-INF/lib directory inside the GeoServer webapps directory. It should be named postgresql-X.X-XXX.jdbc3.jar.

  3. Register the connection pool with the Tomcat Java Naming and Directory Interface (JNDI). This is done by adding a <Resource\> entry to the TOMCAT_HOME/conf/context.xml configuration file. For example, given a PostgreSQL database named test with a user name and password of admin, the configuration would look like this:

    <Context>
     ...
      <Resource name="jdbc/postgres" auth="Container" type="javax.sql.DataSource"
                driverClassName="org.postgresql.Driver"
                url="jdbc:postgresql://localhost:5432/test"
                username="admin" password="admin"
                maxActive="20" maxIdle="10" maxWait="-1"/>
    </Context>
    

    Note

    For more information about the possible parameters and their values refer to the DBCP documentation.

  4. When adding a store in GeoServer, select the JNDI option. Enter the following information:

    • The jndiReferenceName used by the application server.
    • The schema used by the database.

    Using the configuration example above, the jndiReferenceName would be java:comp/env/jdbc/postgres.

For more information, including how to configure JNDI for Oracle and SQL Server data sources, see the GeoServer user manual.