You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Mahoney <pt...@xact.co.uk> on 2004/03/15 20:28:24 UTC

Problem using JNDI/DBCP to get DataSouce

My code looks up a DataSource instance using JNDI. It get an instance but
all the fields are default or null values. When I try to get a connection I
get the error
 Exception: Cannot create JDBC driver of class '' for connect URL 'null'
Its like it finds my configured resource, but the server has not initialised
it...

I have followed the How-To's and gone through it all countless times. I
can't get tomcat to give me any debug or extra logging to help me track the
cause. Below are the gory details for those that can help me (please!!!)

Version - Tomcat 4.1.24

Web.xml (last part as to DTD)
-----------------------------
  <resource-ref>
    <description>Reference to factory javax.sql.DataSource to create
connection instances for OSCARS</description>
    <res-ref-name>jdbc/OscarsDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
------------------------------

Server.xml
-------------------------------
  <GlobalNamingResources>
    <Environment name="simpleValue" override="true" type="java.lang.Integer"
value="30"/>
    <Resource auth="Container" description="User database that can be
updated and saved" name="UserDatabase" scope="Shareable"
type="org.apache.catalina.UserDatabase"/>
    <Resource auth="Container" name="jdbc/OscarsDB" scope="Shareable"
type="javax.sql.DataSource"/>
    <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>
    <ResourceParams name="jdbc/OscarsDB">
      <parameter>
        <name>url</name>
 
<value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFORMIXSERVER=os
cars_dbsrv</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>notreal</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>10</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>trip</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
---------------------------------------

Code extract
---------------------------------------
    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;
  }
-------------------------------

End of message, thank you for your time

Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Paul Mahoney <pt...@xact.co.uk>.
Tried
  dataSource = (DataSource) initContext.lookup("java:comp/jdbc/OscarsDB");
But it return null, so tried
  dataSource = (DataSource)
initContext.lookup("java:comp/env/jdbc/OscarsDB");
And a datasource instance was return so before, looking good...
However, still got the same exception when trying to get a connection
instance
  "Cannot get a connection, pool exhausted"
with a nested exception
  "Could not create a validated object"


>-----Original Message-----
>From: Parsons Technical Services 
>[mailto:parsonstechnical@earthlink.net] 
>Sent: 17 March 2004 16:49
>To: Tomcat Users List; ptm@xact.co.uk
>Subject: Re: Problem using JNDI/DBCP to get DataSouce
>
>
>Paul,
>
>Replace this:
>          if (dataSource == null)
>          {
>            Context initContext = new InitialContext ();
>            Context envContext = (Context) initContext.lookup
>("java:comp/env");
>            dataSource = (DataSource) envContext.lookup 
>("jdbc/OscarsDB");
>          }
>
>With this:
>         if (dataSource == null)
>          {
>            Context initContext = new InitialContext ();
>            dataSource = (DataSource) initContext.lookup
>("java:comp/jdbc/OscarsDB");
>          }
>
>This is working fine for me. Just a note that I am running against MySQL,
>but at this point in the code it should not matter especially since the
>hardwire way works.
>
>Doug


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
Paul,

Replace this:
          if (dataSource == null)
          {
            Context initContext = new InitialContext ();
            Context envContext = (Context) initContext.lookup
("java:comp/env");
            dataSource = (DataSource) envContext.lookup ("jdbc/OscarsDB");
          }

With this:
         if (dataSource == null)
          {
            Context initContext = new InitialContext ();
            dataSource = (DataSource) initContext.lookup
("java:comp/jdbc/OscarsDB");
          }

This is working fine for me. Just a note that I am running against MySQL,
but at this point in the code it should not matter especially since the
hardwire way works.

Doug

----- Original Message ----- 
From: "Paul Mahoney" <pt...@xact.co.uk>
To: "'Parsons Technical Services'" <pa...@earthlink.net>;
"'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Wednesday, March 17, 2004 11:24 AM
Subject: RE: Problem using JNDI/DBCP to get DataSouce


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:parsonstechnical@earthlink.net]
>Sent: 17 March 2004 16:01
>To: Tomcat Users List; ptm@xact.co.uk
>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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
Alex,

Chase the thread. He is on 4.1.30 and no the pool does not work at all.

Doug


----- Original Message ----- 
From: "Alex" <al...@squigly.net>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Wednesday, March 17, 2004 11:19 AM
Subject: RE: Problem using JNDI/DBCP to get DataSouce


> This is what version?  I have issues still with 5.0.19 but my connection
> pools still work despite the error being thrown in the log...does your
> pool just not work at all?
>
> On Wed, 17 Mar 2004, Paul Mahoney wrote:
>
> > Date: Wed, 17 Mar 2004 16:24:08 -0000
> > From: Paul Mahoney <pt...@xact.co.uk>
> > Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
ptm@xact.co.uk
> > To: 'Parsons Technical Services' <pa...@earthlink.net>,
> >      'Tomcat Users List' <to...@jakarta.apache.org>
> > Subject: RE: Problem using JNDI/DBCP to get DataSouce
> >
> > 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>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Alex <al...@squigly.net>.
This is what version?  I have issues still with 5.0.19 but my connection
pools still work despite the error being thrown in the log...does your
pool just not work at all?

On Wed, 17 Mar 2004, Paul Mahoney wrote:

> Date: Wed, 17 Mar 2004 16:24:08 -0000
> From: Paul Mahoney <pt...@xact.co.uk>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>, ptm@xact.co.uk
> To: 'Parsons Technical Services' <pa...@earthlink.net>,
>      'Tomcat Users List' <to...@jakarta.apache.org>
> Subject: RE: Problem using JNDI/DBCP to get DataSouce
>
> 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>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Paul Mahoney <pt...@xact.co.uk>.
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:parsonstechnical@earthlink.net] 
>Sent: 17 March 2004 16:01
>To: Tomcat Users List; ptm@xact.co.uk
>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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
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


----- Original Message ----- 
From: "Paul Mahoney" <pt...@xact.co.uk>
To: "'Parsons Technical Services'" <pa...@earthlink.net>;
"'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Wednesday, March 17, 2004 8:35 AM
Subject: RE: Problem using JNDI/DBCP to get DataSouce


Some progress but still not working.

1. Using my connection parameters I can open a connection to the database in
the standard JDBC way.

2. I have to moved the DataSource configuration from GlobalNamingResources
to the apps Context area of server.xml. This seems to have allowed the JNDI
look-up to work. I now get a DataSource instance with sensible contents.

3. But when I ask for a connection it throws
    "Cannot get a connection, pool exhausted"
   with a nested exception
    "Could not create a validated object"

Beginning to think it's not me but the tomcat server. I'm now moved to
4.1.24 to 4.1.30 but no improvement :(


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Paul Mahoney <pt...@xact.co.uk>.
Some progress but still not working.

1. Using my connection parameters I can open a connection to the database in
the standard JDBC way.

2. I have to moved the DataSource configuration from GlobalNamingResources
to the apps Context area of server.xml. This seems to have allowed the JNDI
look-up to work. I now get a DataSource instance with sensible contents.

3. But when I ask for a connection it throws
    "Cannot get a connection, pool exhausted"
   with a nested exception
    "Could not create a validated object"

Beginning to think it's not me but the tomcat server. I'm now moved to
4.1.24 to 4.1.30 but no improvement :(


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
Not that I am aware of.

Any luck with the other thing to try?

Doug

----- Original Message ----- 
From: "Paul Mahoney" <pt...@xact.co.uk>
To: "'Parsons Technical Services'" <pa...@earthlink.net>;
"'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Monday, March 15, 2004 5:31 PM
Subject: [BULK] - RE: Problem using JNDI/DBCP to get DataSouce


> Thanks for the tip. I put it in the server.xml in the /CustomFares context
> but it didn't help. Is there are equivalent entry for the web.xml file?
>
> >-----Original Message-----
> >From: Parsons Technical Services
> >[mailto:parsonstechnical@earthlink.net]
> >Sent: 15 March 2004 20:55
> >To: Tomcat Users List; ptm@xact.co.uk
> >Subject: Re: Problem using JNDI/DBCP to get DataSouce
> >
> >
> >Paul,
> >
> >Add this to the context for each application that needs the database.
> >
> ><ResourceLink name="jdbc/OscarsDB" global="jdbc/OscarsDB"
> >type="javax.sql.DataSource"/>
> >
> >Doug Parsons
> >www.parsonstechnical.com
> >
> >
> >
> >----- Original Message ----- 
> >From: "Paul Mahoney" <pt...@xact.co.uk>
> >To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> >Sent: Monday, March 15, 2004 2:28 PM
> >Subject: Problem using JNDI/DBCP to get DataSouce
> >
> >
> >My code looks up a DataSource instance using JNDI. It get an
> >instance but
> >all the fields are default or null values. When I try to get a
> >connection I
> >get the error
> > Exception: Cannot create JDBC driver of class '' for connect
> >URL 'null'
> >Its like it finds my configured resource, but the server has
> >not initialised
> >it...
> >
> >I have followed the How-To's and gone through it all countless times. I
> >can't get tomcat to give me any debug or extra logging to help
> >me track the
> >cause. Below are the gory details for those that can help me
> >(please!!!)
> >
> >Version - Tomcat 4.1.24
> >
> >Web.xml (last part as to DTD)
> >-----------------------------
> >  <resource-ref>
> >    <description>Reference to factory javax.sql.DataSource to create
> >connection instances for OSCARS</description>
> >    <res-ref-name>jdbc/OscarsDB</res-ref-name>
> >    <res-type>javax.sql.DataSource</res-type>
> >    <res-auth>Container</res-auth>
> >  </resource-ref>
> >------------------------------
> >
> >Server.xml
> >-------------------------------
> >  <GlobalNamingResources>
> >    <Environment name="simpleValue" override="true"
> >type="java.lang.Integer"
> >value="30"/>
> >    <Resource auth="Container" description="User database that can be
> >updated and saved" name="UserDatabase" scope="Shareable"
> >type="org.apache.catalina.UserDatabase"/>
> >    <Resource auth="Container" name="jdbc/OscarsDB" scope="Shareable"
> >type="javax.sql.DataSource"/>
> >    <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>
> >    <ResourceParams name="jdbc/OscarsDB">
> >      <parameter>
> >        <name>url</name>
> >
> ><value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFO
> >RMIXSERVER=os
> >cars_dbsrv</value>
> >      </parameter>
> >      <parameter>
> >        <name>password</name>
> >        <value>notreal</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxActive</name>
> >        <value>10</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>trip</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxIdle</name>
> >        <value>2</value>
> >      </parameter>
> >    </ResourceParams>
> >  </GlobalNamingResources>
> >---------------------------------------
> >
> >Code extract
> >---------------------------------------
> >    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;
> >  }
> >-------------------------------
> >
> >End of message, thank you for your time
> >
> >Paul
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
Paul

Not that I am aware of. In TC5 you are suppose to be able to do server.xml
fragments. Will be going there soon.

Some things to try:

Reboot.

Recheck logs.

Not sure if order of elements in server.xml is important, try grouping the
<Resource auth=...... with the <ResourceParams......

Try a direct connect without the connection pool. Confirms all other data is
correct.

Where are the jdbc drivers located? I believe they need to be in common/lib
for a GlobalDataSource.

Check spelling and capitalization.

Confirm the syntax on this:
<value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFO
RMIXSERVER=oscars_dbsrv</value>

Looks like you have missed something and concatenated to lines.

Try just this:
<value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars</value>

Mine looks like this:
<value>jdbc:mysql://172.16.1.1:3306/golf?autoReconnect=true</value>

All else fails, go back and start over and set it up EXACTLY like the
example how-to. Then try making minor changes. Yes, I know you will have to
substitute the correct drivers. After you get it working in one context then
try setting up the Global one.

Doug

----- Original Message ----- 
From: "Paul Mahoney" <pt...@xact.co.uk>
To: "'Parsons Technical Services'" <pa...@earthlink.net>;
"'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Monday, March 15, 2004 5:31 PM
Subject: RE: Problem using JNDI/DBCP to get DataSouce


> Thanks for the tip. I put it in the server.xml in the /CustomFares context
> but it didn't help. Is there are equivalent entry for the web.xml file?
>
> >-----Original Message-----
> >From: Parsons Technical Services
> >[mailto:parsonstechnical@earthlink.net]
> >Sent: 15 March 2004 20:55
> >To: Tomcat Users List; ptm@xact.co.uk
> >Subject: Re: Problem using JNDI/DBCP to get DataSouce
> >
> >
> >Paul,
> >
> >Add this to the context for each application that needs the database.
> >
> ><ResourceLink name="jdbc/OscarsDB" global="jdbc/OscarsDB"
> >type="javax.sql.DataSource"/>
> >
> >Doug Parsons
> >www.parsonstechnical.com
> >
> >
> >
> >----- Original Message ----- 
> >From: "Paul Mahoney" <pt...@xact.co.uk>
> >To: "'Tomcat Users List'" <to...@jakarta.apache.org>
> >Sent: Monday, March 15, 2004 2:28 PM
> >Subject: Problem using JNDI/DBCP to get DataSouce
> >
> >
> >My code looks up a DataSource instance using JNDI. It get an
> >instance but
> >all the fields are default or null values. When I try to get a
> >connection I
> >get the error
> > Exception: Cannot create JDBC driver of class '' for connect
> >URL 'null'
> >Its like it finds my configured resource, but the server has
> >not initialised
> >it...
> >
> >I have followed the How-To's and gone through it all countless times. I
> >can't get tomcat to give me any debug or extra logging to help
> >me track the
> >cause. Below are the gory details for those that can help me
> >(please!!!)
> >
> >Version - Tomcat 4.1.24
> >
> >Web.xml (last part as to DTD)
> >-----------------------------
> >  <resource-ref>
> >    <description>Reference to factory javax.sql.DataSource to create
> >connection instances for OSCARS</description>
> >    <res-ref-name>jdbc/OscarsDB</res-ref-name>
> >    <res-type>javax.sql.DataSource</res-type>
> >    <res-auth>Container</res-auth>
> >  </resource-ref>
> >------------------------------
> >
> >Server.xml
> >-------------------------------
> >  <GlobalNamingResources>
> >    <Environment name="simpleValue" override="true"
> >type="java.lang.Integer"
> >value="30"/>
> >    <Resource auth="Container" description="User database that can be
> >updated and saved" name="UserDatabase" scope="Shareable"
> >type="org.apache.catalina.UserDatabase"/>
> >    <Resource auth="Container" name="jdbc/OscarsDB" scope="Shareable"
> >type="javax.sql.DataSource"/>
> >    <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>
> >    <ResourceParams name="jdbc/OscarsDB">
> >      <parameter>
> >        <name>url</name>
> >
> ><value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFO
> >RMIXSERVER=os
> >cars_dbsrv</value>
> >      </parameter>
> >      <parameter>
> >        <name>password</name>
> >        <value>notreal</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxActive</name>
> >        <value>10</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>trip</value>
> >      </parameter>
> >      <parameter>
> >        <name>maxIdle</name>
> >        <value>2</value>
> >      </parameter>
> >    </ResourceParams>
> >  </GlobalNamingResources>
> >---------------------------------------
> >
> >Code extract
> >---------------------------------------
> >    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;
> >  }
> >-------------------------------
> >
> >End of message, thank you for your time
> >
> >Paul
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Problem using JNDI/DBCP to get DataSouce

Posted by Paul Mahoney <pt...@xact.co.uk>.
Thanks for the tip. I put it in the server.xml in the /CustomFares context
but it didn't help. Is there are equivalent entry for the web.xml file?

>-----Original Message-----
>From: Parsons Technical Services 
>[mailto:parsonstechnical@earthlink.net] 
>Sent: 15 March 2004 20:55
>To: Tomcat Users List; ptm@xact.co.uk
>Subject: Re: Problem using JNDI/DBCP to get DataSouce
>
>
>Paul,
>
>Add this to the context for each application that needs the database.
>
><ResourceLink name="jdbc/OscarsDB" global="jdbc/OscarsDB"
>type="javax.sql.DataSource"/>
>
>Doug Parsons
>www.parsonstechnical.com
>
>
>
>----- Original Message ----- 
>From: "Paul Mahoney" <pt...@xact.co.uk>
>To: "'Tomcat Users List'" <to...@jakarta.apache.org>
>Sent: Monday, March 15, 2004 2:28 PM
>Subject: Problem using JNDI/DBCP to get DataSouce
>
>
>My code looks up a DataSource instance using JNDI. It get an 
>instance but
>all the fields are default or null values. When I try to get a 
>connection I
>get the error
> Exception: Cannot create JDBC driver of class '' for connect 
>URL 'null'
>Its like it finds my configured resource, but the server has 
>not initialised
>it...
>
>I have followed the How-To's and gone through it all countless times. I
>can't get tomcat to give me any debug or extra logging to help 
>me track the
>cause. Below are the gory details for those that can help me 
>(please!!!)
>
>Version - Tomcat 4.1.24
>
>Web.xml (last part as to DTD)
>-----------------------------
>  <resource-ref>
>    <description>Reference to factory javax.sql.DataSource to create
>connection instances for OSCARS</description>
>    <res-ref-name>jdbc/OscarsDB</res-ref-name>
>    <res-type>javax.sql.DataSource</res-type>
>    <res-auth>Container</res-auth>
>  </resource-ref>
>------------------------------
>
>Server.xml
>-------------------------------
>  <GlobalNamingResources>
>    <Environment name="simpleValue" override="true" 
>type="java.lang.Integer"
>value="30"/>
>    <Resource auth="Container" description="User database that can be
>updated and saved" name="UserDatabase" scope="Shareable"
>type="org.apache.catalina.UserDatabase"/>
>    <Resource auth="Container" name="jdbc/OscarsDB" scope="Shareable"
>type="javax.sql.DataSource"/>
>    <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>
>    <ResourceParams name="jdbc/OscarsDB">
>      <parameter>
>        <name>url</name>
>
><value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFO
>RMIXSERVER=os
>cars_dbsrv</value>
>      </parameter>
>      <parameter>
>        <name>password</name>
>        <value>notreal</value>
>      </parameter>
>      <parameter>
>        <name>maxActive</name>
>        <value>10</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>trip</value>
>      </parameter>
>      <parameter>
>        <name>maxIdle</name>
>        <value>2</value>
>      </parameter>
>    </ResourceParams>
>  </GlobalNamingResources>
>---------------------------------------
>
>Code extract
>---------------------------------------
>    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;
>  }
>-------------------------------
>
>End of message, thank you for your time
>
>Paul
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Problem using JNDI/DBCP to get DataSouce

Posted by Parsons Technical Services <pa...@earthlink.net>.
Paul,

Add this to the context for each application that needs the database.

<ResourceLink name="jdbc/OscarsDB" global="jdbc/OscarsDB"
type="javax.sql.DataSource"/>

Doug Parsons
www.parsonstechnical.com



----- Original Message ----- 
From: "Paul Mahoney" <pt...@xact.co.uk>
To: "'Tomcat Users List'" <to...@jakarta.apache.org>
Sent: Monday, March 15, 2004 2:28 PM
Subject: Problem using JNDI/DBCP to get DataSouce


My code looks up a DataSource instance using JNDI. It get an instance but
all the fields are default or null values. When I try to get a connection I
get the error
 Exception: Cannot create JDBC driver of class '' for connect URL 'null'
Its like it finds my configured resource, but the server has not initialised
it...

I have followed the How-To's and gone through it all countless times. I
can't get tomcat to give me any debug or extra logging to help me track the
cause. Below are the gory details for those that can help me (please!!!)

Version - Tomcat 4.1.24

Web.xml (last part as to DTD)
-----------------------------
  <resource-ref>
    <description>Reference to factory javax.sql.DataSource to create
connection instances for OSCARS</description>
    <res-ref-name>jdbc/OscarsDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>
------------------------------

Server.xml
-------------------------------
  <GlobalNamingResources>
    <Environment name="simpleValue" override="true" type="java.lang.Integer"
value="30"/>
    <Resource auth="Container" description="User database that can be
updated and saved" name="UserDatabase" scope="Shareable"
type="org.apache.catalina.UserDatabase"/>
    <Resource auth="Container" name="jdbc/OscarsDB" scope="Shareable"
type="javax.sql.DataSource"/>
    <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>
    <ResourceParams name="jdbc/OscarsDB">
      <parameter>
        <name>url</name>

<value>jdbc:informix-sqli://oscar1.travel2.com:1420/oscars:INFORMIXSERVER=os
cars_dbsrv</value>
      </parameter>
      <parameter>
        <name>password</name>
        <value>notreal</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>10</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>trip</value>
      </parameter>
      <parameter>
        <name>maxIdle</name>
        <value>2</value>
      </parameter>
    </ResourceParams>
  </GlobalNamingResources>
---------------------------------------

Code extract
---------------------------------------
    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;
  }
-------------------------------

End of message, thank you for your time

Paul


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org