JDBC Datasource in Tomcat 8

Official Content
This documentation is valid for:

This document describes step by step How to configure a Java model in GeneXus 8.0 or higher to use a SQL Server JDBC datasource in Tomcat 8, using driver JTDS.

1. Configure \conf\context.xml of your tomcat installation

Add the following code between the <Context> and </Context> tag:

    <Resource name="jdbc/testsql"
                        validationQuery="select 1"
                        maxIdle="4"  />

The fields marked in bold should be replaced with your particular data connection information. The resource name can be anyone, this is an example, and just consider to remember this name in order to use it later in Genexus.

2. Configure \webapps\yourWebapp\web-inf\web.xml

Add the following code between the <web-app> and </web-app> tag:

     <description>DB Connection</description>

3. Copy the driver (jtds1-2.jar) to the \lib folder of your tomcat installation

4. Configure your java model in Genexus:

Edit the application DBMS Options and set the following properties:

Use datasource for web based applications = True
JDBC datasource = java:comp/env/jdbc/testsql

Where jdbc/testsql is the JNDI name of the JDBC Datasource.


In case of Oracle Database, you should also set the JNDI name as follows: java:/comp/env/jdbc/myoracle after you've defined the datasource in your Context (\conf\context.xml of your tomcat installation).

<Resource name="jdbc/myoracle" auth="Container"
              type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver"
              username="yourUserName" password="yourPassword" maxActive="20" maxIdle="10"

Interesting links

Here is the official documentation of how to do this in Tomcat 6, also with other dbms samples, like MySql, Postgresql, and Oracle: