Tomcat generally uses the Apache DBCP component to provide pooling over JDBC drivers (org.apache.commons.dbcp).

Here is a sample of how to setup Tomcat to work with Attunity's JDBC driver and connection pooling. The sample was tested using Tomcat v4.1.


To setup Tomcat/DBCP to work with Attunity's JDBC driver perform the followings:

Add the following lines to the Tomcat's conf/server.xml file within the web application <Context> section:

<Resource name="jdbc/navdemo" auth="SERVLET" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/navdemo"> <parameter><name>driverClassName</name><value>com.attunity.jdbc.NvDriver</value></parameter> <parameter><name>url</name><value>jdbc:attconnect:;DefTdpName=n avdemo</value></parameter>

Here 'navdemo' is the database name (navdemo is a demo database that ships with Attunity Connect). The rest of the information is the class name for the Attunity driver as well as documented connection string (see the documentation for other connect string options).

In the webapps/<your-app>/WEB-INF/web.xml file add a reference to the resource defined above:


And then, a servlet could do something like:

import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.*;
import java.sql.*;

public class JdbcServlet
extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();

Context ctx = null;

try {
ctx = new InitialContext();
} catch (NamingException e) {
out.println("Couldn't build an initial context : " + e);

try {
out.println("Looking up java:comp/env/jdbc/navdemo resource...");
DataSource ds =
(DataSource) ctx.lookup("java:comp/env/jdbc/navdemo");
out.println("Getting connection...");
Connection conn = ds.getConnection();

if (conn == null) {
out.println("Failed to get connection");
out.println("Got Connection "+conn.toString());
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery("select * from nation");
if ( {
out.println("First data value: " + rst.getString(2));
} catch (Exception e) {
out.println("JDBC Exception occurred: " + e);


This servlet prints (using the default navdemo tables) the following text:
Looking up java:comp/env/jdbc/navdemo resource...
Getting connection...
Got Connection org.apache.commons.dbcp.PoolableConnection@1ce1bea
First data value: ALGERIA
It also verifies the use of connection pooling (the server connection is being maintained).