tomcat-users mailing list archives

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

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
know.

Thanks,
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"
type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/election">
       <parameter>
        <name>validationQuery</name>
        <value></value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>5000</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>4</value>
      </parameter>
      <parameter>
        <name>username</name>
        <value>XXXXX</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>YYYYY</value>
      </parameter>
      <parameter>
        <name>url</name>
        <value>jdbc:postgresql://127.0.0.1:5432/voting_demo</value>
      </parameter>
      <parameter>
        <name>driverClassName</name>
        <value>org.postgresql.Driver</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
    </ResourceParams>

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"
                 cachingAllowed="true"
                 charsetMapperClass="org.apache.catalina.util.CharsetMapper"
                 cookies="true" crossContext="false" debug="4"
                 displayName="Voting Demo" docBase="voting"

mapperClass="org.apache.catalina.core.StandardContextMapper"
                 path="/voting" privileged="false" reloadable="true"
                 swallowOutput="false" useNaming="true"
                 wrapperClass="org.apache.catalina.core.StandardWrapper">
          <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"/>
        </Context>

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

  <resource-ref>
    <description>
      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.
    </description>
    <res-ref-name>jdbc/election</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
<

The actual accessing Java code: (snippets only)

1) Accessing the resource: (in the init)

       try
       {
           // Class.forName(driver).newInstance();
           // System.out.println("Loaded the appropriate driver." +
protocol);
           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:
",e);

       }
       log("LoginServlet - Acquired DataSource. ");

At this point, everything looks OK.

2) Getting the connection: (in doGet)

            log("Before Connecting to the election database.");
            conn=ds.getConnection();
            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:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message