JDBC TUTORIAL

Tomcat Configuration Tutorial

Updated: 06 Aug 2024

Installing DataDirect Connect for JDBC

First, install DataDirect Connect for JDBC using the instructions in the DataDirect Connect for JDBC Installation Guide.

Next, copy the DataDirect Connect for JDBC jar files (util.jar, base.jar, db2.jar, informix.jar, oracle.jar, sqlserver.jar, and sybase.jar) from:

install_dir/lib

to:

CATALINA_home/common/lib

where install_dir is your DataDirect Connect for JDBC installation directory and CATALINA_home is your Tomcat installation directory.

If you plan to use DataDirect Spy, you must also copy spy.jar from the install_dir/spy subdirectory of your DataDirect Connect for JDBC installation directory to CATALINA_home/common/lib.

Create an Admin User

To use the Tomcat Administration and Management tools, you must create a user with "admin" and "manager" roles. To do this, follow these steps:

  1. Open the tomcat-users.xml file in the CATALINA_home/conf directory with a text editor.
  2. In this file, add the following entries to create the "admin" and "manager" roles:
  3. <role rolename="manager"/>
    <role rolename="admin"/>

     

  4. In addition, add the following entry to create the "admin" user:
  5. <user username="admin" password="myAdminPwd"
    fullName="Administrator" roles="admin,manager"/>

     

  6. Save and close the file.

Create a Data Source

To create a data source using the Tomcat Administration tool:

  1. Start the Tomcat server by running startup.bat or startup.sh, located in the CATALINA_home/bin subdirectory.

  2. In a web browser, enter the following URL to display the Tomcat main page:

    http://localhost:8080

    For example, the Tomcat main page looks similar to that shown in the following the following figure.

  3. Open the Administration Tool by clicking the Tomcat Administration link in the Administration box, which is located in the top-left of the Tomcat main page. The Tomcat Administration Tool's login screen appears.

  4. Enter the user name and password for the admin account that you created earlier in this procedure. Then, click Login. The main page of the Tomcat Administration Tool appears.

  5. In the left pane, click Data Sources. In the right pane, the Data Sources form appears.

  6. From the Data Source Actions drop-down list, select Create New Data Source. The Create New Data Source form appears.

  7. In this form, specify the following information:
    • JNDI Name: The name of the data source, for example, jdbc/TestDS.

    • Data Source URL: A valid DataDirect Connect for JDBC connection URL, for example, jdbc:datadirect:sqlserver://localhost:1433 is a valid connection URL for the DataDirect Connect for JDBCSQL Server driver. Refer to the DataDirect Connect for JDBC User's Guide and Reference for details on specifying a connection URL.

    • JDBC Driver Class: The class name of the DataDirect Connect for JDBC driver, for example, com.ddtek.jdbc.sqlserver.SQLServerDriver is the class name for the DataDirect Connect for JDBC SQL Server driver. Refer to the DataDirect Connect for JDBC User's Guide and Reference for the class names of other DataDirect Connect for JDBC drivers.

    • User Name: A valid user name for the database server.

    • Password: A valid password for the user name.

  8. Click Save. Then, click Commit Changes to create the data source. The data source definition is saved in the file CATALINA_home/conf/server.xml.

  9. Close the browser window to exit the Administration tool.

Generate the JSP Test Page

You must create a JSP page that uses a data source. A sample JSP test page named TomcatTest.jsp is contained in the TomcatTest.war file, which is available with this document. The TomcatTest.jsp page includes the following code to look up the data source and obtain a connection to the database from the data source.

InitialContext ctxt = new InitialContext ();
DataSource ds = (DataSource)
ctxt.lookup("java:/comp/env/ds/TestDS");
Con = ds.getConnection ();

 

Deploy TomcatTest Web Application to Tomcat Application Server

Copy the TomcatTest.war file, available with this document, to the directory CATALINA_home/webapps.


Map the Data Source

When you created the data source in Step 3, it was created in the global name space. The data source is not visible to the TomcatTest web application. To access the data source from within the TomcatTest web application, you must create a link to the global data source in the TomcatTest context. To do this, follow these steps:

  1. Edit the file CATALINA_home/conf/server.xml by adding the following Context element for TomcatTest in the <host> element:
  2. <Context className="org.apache.catalina.core.StandardContext"
    cachingAllowed="true"
    charsetMapperClass="org.apache.catalina.util.CharsetMapper"
    cookies="true" crossContext="false" debug="0"
    displayName="TomcatTest"
    docBase="C:\Products\Tomcat
         \jakarta-tomcat-4.1.29\webapps\TomcatTest.war"
    mapperClass="org.apache.catalina.core.StandardContextMapper"
    path="/TomcatTest" privileged="false" reloadable="false"
    swallowOutput="false" useNaming="true"
    wrapperClass="org.apache.catalina.core.StandardWrapper">
    <ResourceLink global="jdbc/TestDS" name="ds/TestDS"
    type="javax.sql.DataSource"/>
    </Context>

    NOTES:

    • In the docBase attribute above, modify the path to the TomcatTest.war file to the actual path on your machine.
    • The value of the ResourceLink element above is what maps the global data source name jdbc/TestDS to the local name ds/TestDS used in the TomcatTest web application.

  3. Save the changes to the server.xml file.

Run the TomcatTest Web Application

  1. Start the Tomcat server by running startup.bat or startup.sh, located in the CATALINA_home/bin subdirectory.

  2. Open a web browser and enter the following URL to display the TomcatTest page:
  3. http://localhost:8080/TomcatTest
    The contents of the page display the version information of the driver and the database server to which it connects, if the DataDirect Connect for JDBC driver has been installed and configured correctly. For example, the following figure shows version information for the DataDirect Connect for JDBC SQL Server driver connecting to a database server running Microsoft SQL Server 2000.

1 The steps in this paper were generated using Tomcat version 4.1.29. These steps may vary for other versions of Tomcat.

Connect any application to any data source anywhere

Explore all DataDirect Connectors

Need additional help with your product?

Get Customer Support