Question

Tomcat - Using DB2 and JDBC

Asked by: touquet

Ok here we go.
I have had a ton of problems with tomcat and i now want to use my java servlet to connect to a DB2 database. All i want to do is to display a list of names from the "students" table in the database. The field is "firstname". The name of the database is "books" password is "passwd".

Please reply with all of the steps necessary to get this servlet working. Thank you in advance for your time.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-01-16 at 10:28:54ID20460211
Tags

db2

,

tomcat

,

jdbc

Topic

Application Servers

Participating Experts
2
Points
265
Comments
21

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Tomcat
    Can anyone please tell me how does TomCat perform. What is the maximum concurrent hits it can handle. Does this factor also depend on operating system? If i want to develop my application on Linux with database as oracle and tomcat how much load can Tomcat take. The applicat...
  2. set connection pool for DB2 in Tomcat
    I have a project to migrate my application from Bea Weblogic to Tomcat. I want to setup the Connection pool for DB2 in Tomcat(Maybe in server.xml). Can anybody give me some advice how to setup? Thanks
  3. servlets and tomcat
    hi.. i'm a beginner on servlets and i've installed tomcat.. so i have a question for this: i have a servlet and a form that calls it, but i don't know how to compile it and where i must put the servlet on fact to do the form working as it must work

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: pjedmondPosted on 2003-01-16 at 11:59:09ID: 7743396

OK - some real quick and dirty stuff. The process that you will go through for accessing the database is:

1.  Create an instance of the DB driver. Be aware that there are loads of drivers out there of different types. Go here for an understanding of the driver types:

http://www.cariboulake.com/techinfo/jdbc_driver_types.html

You can get an appropriate DB2 driver from here:

http://industry.java.sun.com/products/jdbc/drivers

2.  Create a connection to the database concerned.

3.  Using the connection, create a query to be run on the database.

4.  Execute the query returning a result set.

Note that the structure of steps 1 and 2 will depend on the particular driver being used. Look at the documentation for the JDBC driver you eventually use.

However, to give you an idea of how it should go, I have put together a little code to give you an idea of the process, tweaked from one of my Poitbase connection scripts.





try
{
     System.out.println("Preparing to open DataBase");
     //****LOCAL CONNECTION****
     String dbURL="jdbc:db2://localhost:3000/books:user=???;password=passwd";
        String dbDriver = "com.ibm.db2.jcc.DB2BaseDataSource";
     //************************
     System.out.println("dbURL is : "+dbURL);
        Class.forName(dbDriver).newInstance();
        System.out.println("Loaded the instantDB JDBC driver.");
        Connection conn = DriverManager.getConnection(dbURL);
        System.out.println("Created and connected to database TimingTest");
     System.out.println("Database opened");
     Statement lsStmt=conn.createStatement();
     ResultSet rs = lsStmt.executeQuery("SELECT *FROM students");
       
        while(rs.next()){
            System.out.println("First name is:"+rs.getString("firstname")+"<BR>");
         }
     System.out.println("Finished inserting Data");
     conn.close();
     System.out.println("DataBase closed");

}
catch (Throwable e)
{
          System.out.println("exception thrown");
        e.printStackTrace();
}




Hope that helps - As I've typed this in directly, I make the disclaimer that I may have made the odd systax error before I get flamed!

 

by: pjedmondPosted on 2003-01-16 at 12:00:08ID: 7743404

Now just insert the above into the servlet.....obviously make sure that the DB itself is running correctly first:)

Have fun:)

 

by: mglxxxPosted on 2003-01-20 at 10:22:28ID: 7762380

Here's my version using DB connection pooling and JNDI
Get the following packages from
http://jakarta.apache.org/commons:
commons-dbcp.jar
commons-pool.jar
commons-collections.jar

These provide the connection pool functionality. Copy
the jars to $CATALINA_HOME/common/lib.

Copy the DB2 driver jar to the same directory. On my
machine the DB2 instance is called db2inst1:
cp ~db2inst1/sqllib/java12/db2java.zip $CATALINA_HOME/common/lib/db2java.jar
Note the extension .jar in the copied file. This is important!

Now configure the datasource for tomcat. Edit $CATALINA_HOME/conf/server.xml and add the following
to the DefaultContext element:

          <Resource name="jdbc/db2ds"
                    auth="Container"
                    type="javax.sql.DataSource" />
          <ResourceParams name="jdbc/db2ds" >
            <parameter>
              <name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter>
              <name>maxActive</name>
              <value>10</value>
            </parameter>
            <parameter>
              <name>maxIdle</name>
              <value>3</value>
            </parameter>
            <parameter>
              <name>maxWait</name>
              <value>10000</value>
            </parameter>
            <parameter>
              <name>username</name>
              <value>db2inst1</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>db2inst1</value>
            </parameter>
            <parameter>
              <name>driverClassName</name>
              <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
            </parameter>
            <parameter>
              <name>url</name>
              <value>jdbc:db2:wasrepos</value>
            </parameter>
         </ResourceParams>

This creates a datasource named "jdbc/db2ds" which connects
to the database catalogued as WASREPOS using the
the user db2inst1 and the password db2inst1.

Now code something which uses this datasource, e.g.

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.sql.*;
import java.sql.Connection;
import java.sql.SQLException;

public class DSTestServlet extends HttpServlet {

    public void doGet(HttpServletRequest req,
                  HttpServletResponse res)
      throws ServletException, IOException {

      String dsName = req.getParameter("ds");
      
      PrintWriter out = res.getWriter();
      res.setContentType("text/html");
      out.println("<html>\n<head>\n<title>DSTestServlet</title>\n</head>");
      out.println("<body style=\"background-color: white;\">");
      if ( dsName == null ) {
          out.println("<h1>Parameter 'ds' is empty.</h1>");
      } else {
          try {
            Context initCtx = new InitialContext();
            Context envCtx = (Context)initCtx.lookup("java:comp/env");

            DataSource ds = (DataSource)envCtx.lookup(dsName);
            Connection conn = ds.getConnection();
            out.println("<h1>Successfully connected to " + dsName +
                      "</h1>");
            conn.close();
            out.println("<h1>Successfully disconnected from " + dsName +
                      "</h1>");
          }
          catch (SQLException e) {
            out.println("<h1>Connect failed: " + e + "</h1>");
          }
          catch (NamingException e) {
            out.println("<h1>NamingException while resolving " + dsName +
                      ": " + e);
          }
            catch (InterruptedException e) { }
      }
      out.println("</body>\n</html>");
      out.close();
      
    }
}

Compile it and install it (i.e create an entry in
the appropriate web.xml for it).
If you haven't done so already, set the DB2 environment
variables. On my machine: . ~db2inst1/sqllib/db2profile
(This is UNIX specific.On Win you'd open a DB2 command
window). If you are on Linux: do an export LD_ASSUME_KERNEL=2.2.5. The DB2 "app" JDBC-driver behaves strange, otherwise.

Restart Tomcat.

Assuming that the DSTestServlet has been deployed
under the context "myapp", you should now be
able to access it and tell it to use the datasource
name "jdbc/db2ds" using: http://localhost:8080/DSTestServlet?ds=jdbc/db2ds

I've tested this setup using Tomcat 4.0.3, DB2 7.2 on
RH Linux 7.2.

If you'd rather use the "net" driver than the "app" driver,
replace the driverClassName in server.xml by
COM.ibm.db2.jdbc.net.DB2Driver and the url by
jdbc:db2://localhost:4777/wasrepos. Remember to start
the DB2 java daemon on the DB server machine,. if you
are using the "net" driver: db2jstrt 4777
 

 

by: touquetPosted on 2003-01-22 at 15:19:34ID: 7786718

/**
 * This is the code for a servlet i want it to connect to our database. We have read that the driver that is specified is included in the very recent version of Java SDK we have installed. If we can work with that one it would be great. Please advise exactly how to alter the code and do anything else needed. Thank you very much.. sorry about the long delay between posts.. been very busy.
 * Creation date: (12/20/2002 9:18:35 AM)
 * @author: BATMAN
 * This servlet will connect to our DB2 database and display the first and last name of each student in the students table
 * Remember: If you compile a servlet and then run it, then want to make changes, you will have to rename the .java file and
 *      recompile the servlet
 */

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;

public class DB2 extends HttpServlet
{
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        {
                doPost(request,response);
        }


        public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
        {
                String usr = "Admin";           //This will need to change
                String passwd = "";             //This will need to change
                PrintWriter out = response.getWriter();
                String FIRSTNAME,LASTNAME;

                try
                {
                Class.forName("com.ibm.DB2.jdbc.app.DB2Driver");                //The DB2 driver will have to go on this line
                Connection con = DriverManager.getConnection("jdbc:odbc:PrototypeBooks",usr,passwd);    //This line will als$
                Statement s = con.createStatement();
                String sql = "SELECT * FROM Students";
                ResultSet rs = s.executeQuery(sql);
                while (rs.next())
                {
                        FIRSTNAME = rs.getString("FIRSTNAME");
                        LASTNAME = rs.getString("LASTNAME");
                        out.println(FIRSTNAME + " " + LASTNAME + "<BR>");
                }
                rs.close();
                s.close();
                con.close();
                }
                catch (ClassNotFoundException e)
                {
                        System.out.println(e.toString());
                }
                catch (SQLException e)
                {
                        System.out.println(e.toString());
                }
                catch (Exception e)
                {
                        System.out.println(e.toString());
                }

           }
}

 

by: mglxxxPosted on 2003-01-22 at 23:57:29ID: 7789610

Using the setup I described in my previous comment
you'll need to do the following:

The resource definition in server.xml would be (adjust
the 'password' parameter to the correct value):

<Resource name="jdbc/PrototypeBooks"
                   auth="Container"
                   type="javax.sql.DataSource" />
         <ResourceParams name="jdbc/PrototypeBooks" >
           <parameter>
             <name>factory</name>
             <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
           </parameter>
           <parameter>
             <name>maxActive</name>
             <value>10</value>
           </parameter>
           <parameter>
             <name>maxIdle</name>
             <value>3</value>
           </parameter>
           <parameter>
             <name>maxWait</name>
             <value>10000</value>
           </parameter>
           <parameter>
             <name>username</name>
             <value>Admin</value>
           </parameter>
           <parameter>
             <name>password</name>
             <value>whatever_you_choose</value>
           </parameter>
           <parameter>
             <name>driverClassName</name>
             <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
           </parameter>
           <parameter>
             <name>url</name>
             <value>jdbc:db2:PrototypeBooks</value>
           </parameter>
        </ResourceParams>


/**
* This is the code for a servlet i want it to connect to our database. We have read that the driver that is specified is included in the very recent version of Java SDK we have installed. If we can work with that one it would be great. Please advise exactly how to alter the code and do anything else needed. Thank you very much.. sorry about the long delay between posts.. been very busy.
* Creation date: (12/20/2002 9:18:35 AM)
* @author: BATMAN
* This servlet will connect to our DB2 database and display the first and last name of each student in the students table
* Remember: If you compile a servlet and then run it, then want to make changes, you will have to rename the .java file and
*      recompile the servlet
*/

import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import java.util.*;
import java.io.*;
import javax.sql.*;
import java.sql.*;

public class DB2 extends HttpServlet
{
       public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
       {
               doPost(request,response);
       }


       public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
       {
               PrintWriter out = response.getWriter();
               String FIRSTNAME,LASTNAME;
               out.println("<html>\n<head>\n<title>" +
                           "Student Names</title>" +
                           "\n</head>\n<body>");

               
               try
               {
               
          Context initCtx = new InitialContext();
          Context envCtx = (Context)initCtx.lookup("java:comp/env");

          DataSource ds = (DataSource)envCtx.lookup("jdbc/PrototypeBooks");
          Connection con = ds.getConnection();

               Statement s = con.createStatement();
               String sql = "SELECT * FROM Students";
               ResultSet rs = s.executeQuery(sql);
               while (rs.next())
               {
                       FIRSTNAME = rs.getString("FIRSTNAME");
                       LASTNAME = rs.getString("LASTNAME");
                       out.println(FIRSTNAME + " " + LASTNAME + "<BR>");
               }
               rs.close();
               s.close();
               con.close();
               }
               catch (NamingException e)
               {
                        out.println("<h1>Failed to resolve datasource</h1>\n<pre>");
                        e.printStackTrace(out);
                        out.println("</pre>");
               }
               catch (SQLException e)
               {
                       out.println("<h1>SQL exception</h1>\n<pre>");
                       e.printStackTrace(out);
                       out.println("</pre>");
               }
               catch (Exception e)
               {
                       out.println("<h1>General exception</h1>\n<pre>");
                       e.printStackTrace(out);
                       out.println("</pre>");
               }
               out.println("</body>\n</html>");

          }
}

 

by: touquetPosted on 2003-01-23 at 11:20:23ID: 7794073

I followed your(mqlxxx) instructions and when i ran the servlet it threw the NamingException what does this mean and how would i fix it???

 

by: mglxxxPosted on 2003-01-23 at 11:28:55ID: 7794131

It means that the servlet couldn't find the
resource named "jdbc/PrototypeBooks" in the JNDI.
This could have several reasons. One of these
could be that the connection pool had a problem.

The server logs could have some pointers.

Could you post a listing of $CATALINA_HOME/common/lib and
the server.xml? This is just to make sure that on
the installation and configuration side everything is
OK.

 

by: touquetPosted on 2003-01-25 at 07:30:41ID: 7808419

contents of common/lib

activation.jar           db2java.jar          mail.jar
ant.jar                  jasper-compiler.jar  naming-common.jar
commons-collections.jar  jasper-runtime.jar   naming-factory.jar
commons-dbcp.jar         jdbc2_0-stdext.jar   naming-resources.jar
commons-logging-api.jar  jndi.jar             servlet.jar
commons-pool.jar         jta.jar


server.xml file

<!-- Example Server Configuration File -->
<!-- Note that component elements are nested corresponding to their
     parent-child relationships with each other -->

<!-- A "Server" is a singleton element that represents the entire JVM,
     which may contain one or more "Service" instances.  The Server
     listens for a shutdown command on the indicated port.

     Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" or "Loggers" at this level.
 -->

<Server port="8005" shutdown="SHUTDOWN" debug="0">


  <!-- Uncomment these entries to enable JMX MBeans support -->
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"
            debug="0"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"
            debug="0"/>

  <!-- Global JNDI resources -->
  <GlobalNamingResources>

    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>

    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users -->
    <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
       description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="UserDatabase">
      <parameter>
        <name>factory</name>
        <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
      </parameter>
      <parameter>
        <name>pathname</name>
        <value>conf/tomcat-users.xml</value>
      </parameter>
    </ResourceParams>

  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" (and therefore the web applications visible
       within that Container).  Normally, that Container is an "Engine",
       but this is not required.

       Note:  A "Service" is not itself a "Container", so you may not
       define subcomponents such as "Valves" or "Loggers" at this level.
   -->

  <!-- Define the Tomcat Stand-Alone Service -->
  <Service name="Tomcat-Standalone">

    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned.  Each Connector passes requests on to the
         associated "Container" (normally an Engine) for processing.

         By default, a non-SSL HTTP/1.1 Connector is established on port 8080.
         You can also enable an SSL HTTP/1.1 Connector on port 8443 by
         following the instructions below and uncommenting the second Connector
         entry.  SSL support requires the following steps (see the SSL Config
         HOWTO in the Tomcat 4.0 documentation bundle for more detailed
         instructions):
         * Download and install JSSE 1.0.2 or later, and put the JAR files
           into "$JAVA_HOME/jre/lib/ext".
         * Execute:
             %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA (Windows)
             $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA  (Unix)
           with a password value of "changeit" for both the certificate and
           the keystore itself.

         By default, DNS lookups are enabled when a web application calls
         request.getRemoteHost().  This can have an adverse impact on
         performance, so you can disable it by setting the
         "enableLookups" attribute to "false".  When DNS lookups are disabled,
         request.getRemoteHost() will return the String version of the
         IP address of the remote client.
    -->

    <!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="80" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="20000"
               useURIValidationHack="false" />
    <!-- Note : To disable connection timeouts, set connectionTimeout value
     to -1 -->

    <!-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
    <!--
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8443" minProcessors="5" maxProcessors="75"
               enableLookups="true"
             acceptCount="10" debug="0" scheme="https" secure="true"
               useURIValidationHack="false">
      <Factory className="org.apache.coyote.tomcat4.CoyoteServerSocketFactory"
               clientAuth="false" protocol="TLS" />
    </Connector>
    -->

    <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 -->
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8009" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" connectionTimeout="20000"
               useURIValidationHack="false"
               protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/>

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
               port="8009" minProcessors="5" maxProcessors="75"
               acceptCount="10" debug="0"/>
    -->

    <!-- Define a Proxied HTTP/1.1 Connector on port 8082 -->
    <!-- See proxy documentation for more information about using this. -->
    <!--
    <Connector className="org.apache.coyote.tomcat4.CoyoteConnector"
               port="8082" minProcessors="5" maxProcessors="75"
               enableLookups="true"
               acceptCount="10" debug="0" connectionTimeout="20000"
               proxyPort="80" useURIValidationHack="false" />
    -->

    <!-- Define a non-SSL legacy HTTP/1.1 Test Connector on port 8083 -->
    <!--
    <Connector className="org.apache.catalina.connector.http.HttpConnector"
               port="8083" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" />
    -->

    <!-- Define a non-SSL HTTP/1.0 Test Connector on port 8084 -->
    <!--
    <Connector className="org.apache.catalina.connector.http10.HttpConnector"
               port="8084" minProcessors="5" maxProcessors="75"
               enableLookups="true" redirectPort="8443"
               acceptCount="10" debug="0" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host). -->

    <!-- Define the top level container in our container hierarchy -->
    <Engine name="Standalone" defaultHost="localhost" debug="0">

      <!-- The request dumper valve dumps useful debugging information about
           the request headers and cookies that were received, and the response
           headers and cookies that were sent, for all requests received by
           this instance of Tomcat.  If you care only about requests to a
           particular virtual host, or a particular application, nest this
           element inside the corresponding <Host> or <Context> entry instead.

           For a similar mechanism that is portable to all Servlet 2.3
           containers, check out the "RequestDumperFilter" Filter in the
           example application (the source for this filter may be found in
           "$CATALINA_HOME/webapps/examples/WEB-INF/classes/filters").

           Request dumping is disabled by default.  Uncomment the following
           element to enable it. -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- Global logger unless overridden at lower levels -->
      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="catalina_log." suffix=".txt"
              timestamp="true"/>

      <!-- Because this Realm is here, an instance will be shared globally -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                 debug="0" resourceName="UserDatabase"/>

      <!-- Comment out the old realm but leave here for now in case we
           need to go back quickly -->
      <!--
      <Realm className="org.apache.catalina.realm.MemoryRealm" />
      -->

      <!-- Replace the above Realm with one of the following to get a Realm
           stored in a database and accessed via JDBC -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
             driverName="org.gjt.mm.mysql.Driver"
          connectionURL="jdbc:mysql://localhost/authority"
         connectionName="test" connectionPassword="test"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
             driverName="oracle.jdbc.driver.OracleDriver"
          connectionURL="jdbc:oracle:thin:@ntserver:1521:ORCL"
         connectionName="scott" connectionPassword="tiger"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!--
      <Realm  className="org.apache.catalina.realm.JDBCRealm" debug="99"
             driverName="sun.jdbc.odbc.JdbcOdbcDriver"
          connectionURL="jdbc:odbc:CATALINA"
              userTable="users" userNameCol="user_name" userCredCol="user_pass"
          userRoleTable="user_roles" roleNameCol="role_name" />
      -->

      <!-- Define the default virtual host -->
      <Host name="localhost" debug="0" appBase="webapps"
       unpackWARs="true" autoDeploy="true">

        <!-- Normally, users must authenticate themselves to each web app
             individually.  Uncomment the following entry if you would like
             a user to be authenticated the first time they encounter a
             resource protected by a security constraint, and then have that
             user identity maintained across *all* web applications contained
             in this virtual host. -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn"
                   debug="0"/>
        -->

        <!-- Access log processes all requests for this virtual host.  By
             default, log files are created in the "logs" directory relative to
             $CATALINA_HOME.  If you wish, you can specify a different
             directory with the "directory" attribute.  Specify either a relative
             (to $CATALINA_HOME) or absolute path to the desired directory.
        -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
        -->

        <!-- Logger shared by all Contexts related to this virtual host.  By
             default (when using FileLogger), log files are created in the "logs"
             directory relative to $CATALINA_HOME.  If you wish, you can specify
             a different directory with the "directory" attribute.  Specify either a
             relative (to $CATALINA_HOME) or absolute path to the desired
             directory.-->
        <Logger className="org.apache.catalina.logger.FileLogger"
                 directory="logs"  prefix="localhost_log." suffix=".txt"
              timestamp="true"/>

        <!-- Define properties for each web application.  This is only needed
             if you want to set non-default properties, or have web application
             document roots in places other than the virtual host's appBase
             directory.  -->


        <!-- Tomcat Root Context -->
          <Context path="" docBase="ROOT" debug="0">
       


         <Resource name="jdbc/PrototypeBooks"
                   auth="Container"
                   type="javax.sql.DataSource" />
         <ResourceParams name="jdbc/PrototypeBooks" >
           <parameter>
             <name>factory</name>
             <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
           </parameter>
           <parameter>
             <name>maxActive</name>
             <value>10</value>
           </parameter>
           <parameter>
             <name>maxIdle</name>
             <value>3</value>
           </parameter>
           <parameter>
             <name>maxWait</name>
             <value>10000</value>
           </parameter>
           <parameter>
             <name>username</name>
             <value>techno</value>
           </parameter>
           <parameter>
             <name>password</name>
             <value>gabbo</value>
           </parameter>
           <parameter>
             <name>driverClassName</name>
             <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
           </parameter>
           <parameter>
             <name>url</name>
             <value>jdbc:db2:bookstr</value>
           </parameter>
        </ResourceParams>
</Context>


      <!-- Tomcat MyApp Context -->
      <Context path="/MyApp" docBase="MyApp" debug="0" reloadable="true"></Context>
        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
                timestamp="true"/>
          <Ejb   name="ejb/EmplRecord" type="Entity"
                 home="com.wombat.empl.EmployeeRecordHome"
               remote="com.wombat.empl.EmployeeRecord"/>

          <!-- If you wanted the examples app to be able to edit the
               user database, you would uncomment the following entry.
               Of course, you would want to enable security on the
               application as well, so this is not done by default!
               The database object could be accessed like this:

               Context initCtx = new InitialContext();
               Context envCtx = (Context) initCtx.lookup("java:comp/env");
               UserDatabase database =
                    (UserDatabase) envCtx.lookup("userDatabase");
          -->
<!--
          <ResourceLink name="userDatabase" global="UserDatabase"
                        type="org.apache.catalina.UserDatabase"/>
-->


          <!-- PersistentManager: Uncomment the section below to test Persistent
                   Sessions.
                         
               saveOnRestart: If true, all active sessions will be saved
                 to the Store when Catalina is shutdown, regardless of
                 other settings. All Sessions found in the Store will be
                 loaded on startup. Sessions past their expiration are
                 ignored in both cases.
               maxActiveSessions: If 0 or greater, having too many active
                 sessions will result in some being swapped out. minIdleSwap
                 limits this. -1 means unlimited sessions are allowed.
                 0 means sessions will almost always be swapped out after
                 use - this will be noticeably slow for your users.
               minIdleSwap: Sessions must be idle for at least this long
                 (in seconds) before they will be swapped out due to
               maxActiveSessions. This avoids thrashing when the site is
                 highly active. -1 or 0 means there is no minimum - sessions
                 can be swapped out at any time.
               maxIdleSwap: Sessions will be swapped out if idle for this
                 long (in seconds). If minIdleSwap is higher, then it will
                 override this. This isn't exact: it is checked periodically.
                 -1 means sessions won't be swapped out for this reason,
                 although they may be swapped out for maxActiveSessions.
                 If set to >= 0, guarantees that all sessions found in the
                 Store will be loaded on startup.
               maxIdleBackup: Sessions will be backed up (saved to the Store,
                 but left in active memory) if idle for this long (in seconds),
                 and all sessions found in the Store will be loaded on startup.
                 If set to -1 sessions will not be backed up, 0 means they
                 should be backed up shortly after being used.

               To clear sessions from the Store, set maxActiveSessions, maxIdleSwap,
               and minIdleBackup all to -1, saveOnRestart to false, then restart
               Catalina.
          -->
              <!--
          <Manager className="org.apache.catalina.session.PersistentManager"
              debug="0"
              saveOnRestart="true"
              maxActiveSessions="-1"
              minIdleSwap="-1"
              maxIdleSwap="-1"
              maxIdleBackup="-1">
                <Store className="org.apache.catalina.session.FileStore"/>
          </Manager>
              -->
          <Environment name="maxExemptions" type="java.lang.Integer"
                      value="15"/>
          <Parameter name="context.param.name" value="context.param.value"
                     override="false"/>
          <Resource name="jdbc/EmployeeAppDb" auth="SERVLET"
                    type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/EmployeeAppDb">
            <parameter><name>username</name><value>sa</value></parameter>
            <parameter><name>password</name><value></value></parameter>
            <parameter><name>driverClassName</name>
              <value>org.hsql.jdbcDriver</value></parameter>
            <parameter><name>url</name>
              <value>jdbc:HypersonicSQL:database</value></parameter>
          </ResourceParams>
          <Resource name="mail/Session" auth="Container"
                    type="javax.mail.Session"/>
          <ResourceParams name="mail/Session">
            <parameter>
              <name>mail.smtp.host</name>
              <value>localhost</value>
            </parameter>
          </ResourceParams>
          <ResourceLink name="linkToGlobalResource"
                    global="simpleValue"
                    type="java.lang.Integer"/>
        </Context>

      </Host>

    </Engine>

  </Service>

  <!-- The MOD_WEBAPP connector is used to connect Apache 1.3 with Tomcat 4.0
       as its servlet container. Please read the README.txt file coming with
       the WebApp Module distribution on how to build it.
       (Or check out the "jakarta-tomcat-connectors/webapp" CVS repository)

       To configure the Apache side, you must ensure that you have the
       "ServerName" and "Port" directives defined in "httpd.conf".  Then,
       lines like these to the bottom of your "httpd.conf" file:

         LoadModule webapp_module libexec/mod_webapp.so
         WebAppConnection warpConnection warp localhost:8008
         WebAppDeploy examples warpConnection /examples/

       The next time you restart Apache (after restarting Tomcat, if needed)
       the connection will be established, and all applications you make
       visible via "WebAppDeploy" directives can be accessed through Apache.
  -->

  <!-- Define an Apache-Connector Service -->
<!--
  <Service name="Tomcat-Apache">

    <Connector className="org.apache.catalina.connector.warp.WarpConnector"
     port="8008" minProcessors="5" maxProcessors="75"
     enableLookups="true" appBase="webapps"
     acceptCount="10" debug="0"/>

    <Engine className="org.apache.catalina.connector.warp.WarpEngine"
     name="Apache" debug="0">

      <Logger className="org.apache.catalina.logger.FileLogger"
              prefix="apache_log." suffix=".txt"
              timestamp="true"/>

      <Realm className="org.apache.catalina.realm.MemoryRealm" />

    </Engine>

  </Service>
-->

</Server>

 

by: mglxxxPosted on 2003-01-26 at 22:52:04ID: 7819187

The installation and configuration looks OK to me.
Did you install your servlet into the root
context? If not, this could be the problem.

You can define the DataSource in a 'DefaultContext'
element in order to make it available to all
contexts.

 

by: touquetPosted on 2003-01-27 at 02:31:43ID: 7820102

ok that actually was the problem. I moved the prototype definition to the MyApp directory and it worked.. i should have got that one on my own.. oh well.. New problem.. Now i get this error

SQL ERROR

java.sql.SQLException: Cannot create JDBC driver of class 'COM.ibm.db2.jdbc.app.DB2Driver' for connect URL 'jdbc:db2:bookstr'

 

by: mglxxxPosted on 2003-01-27 at 02:49:43ID: 7820193

Do you get any other messages like 'class not found' or
'unsatisfied link'?.

It might be a problem with the DB2 environment.

Which OS are you using?
Is the DB2 database on the same machine as Tomcat?

 

by: touquetPosted on 2003-01-27 at 02:56:07ID: 7820209

no other errors that i know of.. we are running slackware 8 and both the database and tomcat are on the same machine

 

by: mglxxxPosted on 2003-01-27 at 03:24:54ID: 7820327

Did you remember to set the DB2 environment for the
user tomcat is running under?

To check this try a
db2 connect to bookstr user techno using gabbo
before starting tomcat. If this works, the JDBC-driver
most likely doesn't like slackware. Workaround:

Become the DB2 instance owner. Do a db2jstrt 4777 (or
any other unused port).
Modify your server.xml to use the 'net' driver, which
doesn't contain any native code.

Following parameters in the resource definition should
be changed:

driverClassName: COM.ibm.db2.jdbc.net.DB2Driver
url: jdbc:db2://localhost:4777/bookstr

 

by: mglxxxPosted on 2003-01-27 at 03:27:46ID: 7820346

Also check for error messages in
$CATALINA_HOME/logs/catalina_log.txt
and
$CATALINA_HOME/logs/localhost_log.txt

 

by: touquetPosted on 2003-01-27 at 16:41:54ID: 7826039

ok i changed those two lines and ran the command specified to get around the driver not likeing slackware. Now i get this error

General exception

org.apache.commons.dbcp.DbcpException: COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0621E  Unsupported JDBC Server configuration.

 

 

by: mglxxxPosted on 2003-01-27 at 23:20:31ID: 7827881

I haven't seen this before.
If you copied the db2java.zip from sqllib/java12:
Become the instance owner.
Kill the db2jd -- it needs a SIGKILL to terminate.
Do a
. sqllib/java12/usejdbc2
This makes the db2jd use the db2java.zip in sqllib/java12.
Restart the db2jd: db2jstrt 4777

Become the Tomcat user and restart Tomcat.

For details see:
http://www-3.ibm.com/cgi-bin/db2www/data/db2/udb/winos2unix/support/v8infocenter.d2w/report?target=mainFrame&fn=c0006310.htm

 

by: touquetPosted on 2003-01-28 at 18:50:26ID: 7834661

ok well here's another error.. still a General Exception

org.apache.commons.dbcp.DbcpException: COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0616E  Error opening socket. SQLSTATE=08S01

 

by: mglxxxPosted on 2003-01-28 at 23:07:05ID: 7835670

Are you sure you started the db2jd on the correct port?
The error message means that there was nobody listening
on the host and the port specified in the url.

Also check the db2jd error log in
<instance_home>/sqllib/jdbcerr.log

 

by: touquetPosted on 2003-01-29 at 07:11:58ID: 7838353

THANK YOU SO VERY VERY MUCH.. you are my hero!

 

by: touquetPosted on 2003-01-29 at 07:13:14ID: 7838366

Thank you so very much... you are definately my hero

 

by: mglxxxPosted on 2003-01-29 at 07:52:43ID: 7838773

You're welcome. Thanks for the points!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...