Unofficial Content

Defining a JDBC Datasource in Jakarta Tomcat 4.x

Scope: GeneXus Java 8.0 or higher and Jakarta Tomcat 4x

First Step
This can also be done from Tomcat Administrative Console. The main difference will be that in this case, the JNDI will be available for the entire server (all web apps) instead of being available for a specific Context.

In order to do this just Start Tomcat and enter the following URL: http://localhost:8080/admin

  • Click the option "Data Sources" and choose the option "Create New Data Source"
  • Enter the needed information with your specific information as shown in the image below. This data source is defined as an example for SQL Server

First Step (The same editing system files - Recommended for advanced users only)
Edit the file TOMCAT_HOME\conf\server.xml.
Find your application context definition within the <Context> and </Context> tags.
Once you find it paste the following before the tag </Context>

<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"/>
 <ResourceParams name="jdbc/TestDB"> 

Where jdbc/TestDB is the JNDI name of the JDBC Datasource.
In this case, it's a definition of a data source pointing to an SQL Server.
Fields in bold should be modified with your specific information.


  • With the declaration above, a SQL error might be generated if there is no SelectMethod information in the url value (for MS SqlServer). Try with:
  • Sometimes, there is no Context declaration for our web app in TOMCAT_HOME\conf\server.xml file, and the data source is declared as a global resource. In this case, we could create the context information for the web app with a link to the global data source inside. Something like this:
<Context docBase="<webapp>" path="/<webapp>" workDir="work/Catalina/localhost/<webapp>"> 
 <ResourceLink name="jdbc/TestDB" global="jdbc/TestDB" type="javax.sql.DataSource" />  

This Context definition should be stated between the <host></host> tags.

Second Step
Edit the file TOMCAT_HOME\webapps\<YOUR_WEBAPP>\WEB-INF\web.xml.
Add the following piece of code before the </webapp> tag:

     <description>DB Connection</description> 

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

Third Step
Copy the JDBC Driver libraries into the TOMCAT_HOME\common\lib.

Fourth Step
Edit the application DBMS Options and set the following properties:

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

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