tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steve Carrow" <>
Subject PostgreSQL JNDI resource under Tomcat 4.1.12 problem
Date Thu, 10 Oct 2002 01:11:25 GMT

I'm trying to run a web app under Tomcat 4.1.12 with a PostgreSQL JNDI
resource. When I use DriverManager directly, the DB works fine, but when I
try to access it as a resource, the servlet seems to hang when it tries to
acquire a connection from the datasource. Following are the relevant (I
believe) pieces of server.xml concerning the resource and the context, as
well as the snippets of Java code used to access the resource and the
web.xml resource-ref entry. Again, the DB itself can be accessed from both
the command line and the servlet IF I use DriverManager directly. I've been
beating my head against this one for a while; please demonstrate for me the
full extent of my moroninity.-)) If more info is required, please let me

Steve Carrow

Server.xml: This portion exists under the GlobalNamingResources element
under Server; the only pieces changed are the username and password.-)

    <Resource name="jdbc/election" scope="Shareable"
    <ResourceParams name="jdbc/election">

This part defines the context of the web app. It exists under the default
Host, Engine, and Service.

        <Context className="org.apache.catalina.core.StandardContext"
                 cookies="true" crossContext="false" debug="4"
                 displayName="Voting Demo" docBase="voting"

                 path="/voting" privileged="false" reloadable="true"
                 swallowOutput="false" useNaming="true"
          <ResourceLink name="jdbc/election" global="jdbc/election"
type="javax.sql.DataSource" />
          <Logger className="org.apache.catalina.logger.FileLogger"
debug="0" directory="logs" prefix="localhost_voting_log." suffix=".txt"
timestamp="true" verbosity="1"/>

>From the web.xml file: (is this entry necessary?)

      Resource reference to a factory for java.sql.Connection
      instances that may be used for talking to a particular
      database that is configured in the server.xml file.

The actual accessing Java code: (snippets only)

1) Accessing the resource: (in the init)

           // Class.forName(driver).newInstance();
           // System.out.println("Loaded the appropriate driver." +
           ctx=new InitialContext();
           log("LoginServlet - Before Lookup. ");
           ds = (DataSource) ctx.lookup("java:comp/env/jdbc/election");
           log("LoginServlet - After Lookup. ");
           if (ds == null)
              throw new ServletException("LoginServlet - Failed to acquire
DataSource. ");
       catch (Exception e)
            log("Can not load the appropriate driver!", e);
            throw new ServletException("LoginServlet - Other exception:

       log("LoginServlet - Acquired DataSource. ");

At this point, everything looks OK.

2) Getting the connection: (in doGet)

            log("Before Connecting to the election database.");
            log("Connected to the election database.");

The app never gets to the senond log line of this section, and from the
browser prespective, it simply hangs.

Thanks again.

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message