Here goes.... Cut and paste, but blanked out the password bits.
I hope your eyes can spy the problem. I assume you have this working :)

Server.xml (the Context bit)
-----------------------------
        <Context className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true"
crossContext="false" debug="0" displayName="Custom Fares"
docBase="C:/Documents and Settings/pmahoney/My Documents/Travel
2/code/webapps/CustomFares/web"
mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/CustomFares" privileged="false" reloadable="false"
swallowOutput="false" useNaming="true"
wrapperClass="org.apache.catalina.core.StandardWrapper">
          <Resource name="jdbc/OscarsDB" scope="Shareable"
type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/OscarsDB">
            <parameter>
              <name>validationQuery</name>
              <value>select count(*) from systables</value>
            </parameter>
            <parameter>
              <name>url</name>
 
<value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFORMIXSERVER=os
cars_dbsrv</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>??????</value>
            </parameter>
            <parameter>
              <name>maxActive</name>
              <value>4</value>
            </parameter>
            <parameter>
              <name>maxWait</name>
              <value>5000</value>
            </parameter>
            <parameter>
              <name>driverClassName</name>
              <value>com.informix.jdbc.IfxDriver</value>
            </parameter>
            <parameter>
              <name>username</name>
              <value>sy5t3m</value>
            </parameter>
            <parameter>
              <name>maxIdle</name>
              <value>2</value>
            </parameter>
          </ResourceParams>
        </Context>

Web.xml (the resource reference bit)
------------------------------------
...
<!-- Comment out now DataSource resource configured in server.xml <Context>
  <resource-ref>
    <description>Connection pool for OSCARS database</description>
    <res-ref-name>jdbc/OscarsDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
  -->
</web-app>

The code 
--------
  // The JNDI way...
  protected Connection getJdbcConnection ()
          throws SQLException
  {
    Connection connection = null;

    // First we need to locate the JNDI data source
    if (dataSource == null)
    {
      try
      {
        synchronized (this)
        {
          if (dataSource == null)
          {
            Context initContext = new InitialContext ();
            Context envContext = (Context) initContext.lookup
("java:comp/env");
            dataSource = (DataSource) envContext.lookup ("jdbc/OscarsDB");
          }
        }
      }
      catch (NamingException ne)
      {
        // wrap it up in an SQLException to keep calling code simple
        SQLException se = new SQLException ("JNDI Data Source lookup
failed");
        se.initCause (ne);
        throw se;
      }
    }

    try
    {
      connection = dataSource.getConnection ();
    }
    catch (SQLException se)
    {
      throw se;
    }

    return connection;
  }

  // Hardwired the old way...
  protected Connection getOscarsConnection ()
    throws SQLException
  {
    Connection connection = null;
    try
    {
      Properties props = new Properties();

      props.put("user", "sy5t3m");
      props.put("password", "??????");

      Class.forName("com.informix.jdbc.IfxDriver");
      connection = DriverManager.getConnection(
 
"jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFORMIXSERVER=oscars_d
bsrv",
            props);
    }
    catch (ClassNotFoundException cnfe)
    {
      System.err.println  ("Error: Class not found: "
                           + cnfe.getMessage()
                          );
    }
    catch (SQLException se)
    {
      System.err.println  ("Error: while accessing database: "
                           + se.getMessage()
                          );
      while ((se = se.getNextException()) != null)
      {
        System.err.println("   next: " + se.getMessage());
      }
    }

    return connection;
  }

  public String execute ()
    throws Exception
  {
    Connection connection = null;

    try
    {
      connection = getJdbcConnection();
//      connection = getOscarsConnection();
    }
    catch (Exception e)
    {
      throw e;
    }
    finally // must release the following resources if acquired...
    {
        if (connection != null)
        {
          try { connection.close (); }  catch (Exception e)     {
e.printStackTrace ();   }
        }
    }

    return "<Fare></Fare>"; // empty for now
  }
}

>-----Original Message-----
>From: Parsons Technical Services 
>[mailto:[EMAIL PROTECTED] 
>Sent: 17 March 2004 16:01
>To: Tomcat Users List; [EMAIL PROTECTED]
>Subject: Re: Problem using JNDI/DBCP to get DataSouce
>
>
>Paul,
>
>Since you have done several changes, please repost your current context
>section of the server.xml, exception you receive and code you use to access
>the DB both with conventional JDBC and DBCP. At this point it sounds like a
>typo that's preventing the connection pool from connecting to the database.
>
>Doug
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to