You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andrew D Johnson <ad...@us.ibm.com> on 2002/11/11 19:25:48 UTC

Problems with DB2ConnectionPoolDataSource - "Cannot create JDBC driver"

I'm trying to configure Tomcat to use a DB2ConnectionPoolDataSource, but
I'm experiencing problems which appear to be related to configuration -
more specifically the datasource I've defined in the server.xml file, and
the datasource returned from the InitialContext within the code are
different.  I receive a "Cannot create JDBC driver of class
'COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource' " exception

Maybe this situation is best described with code.

In server.xml
<Context path="/emsl" docBase="emsl" debug="0" reloadable="true"
crossContext="true">
<Resource name="jdbc/emsltestds" auth="SERVLET" type
="javax.sql.DataSource"/>
<ResourceParams name="jdbc/emsltestds">
<parameter>
<name>user</name><value>username</value>
</parameter>
<parameter>
<name>password</name><value>userpassword</value></parameter>
<parameter>
<name>driverClassName</name><value>COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource</value>
</parameter>
<parameter>
<name>driverName</name><value>jdbc:db2:rtmwasdb</value>
</parameter>
<parameter>
<name>url</name><value>//9.17.41.96:50000</value>
</parameter>
</ResourceParams>
</Context>

In web.xml
<resource-ref>
<description>DB2 Connection</description>
<res-ref-name>jdbc/emsltestds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

the code in my servlet
try {
      Context jndiCntx = new InitialContext();
      out.println("new InitialContext<br>");
      DataSource ds = (DataSource)jndiCntx.lookup
("java:comp/env/jdbc/emsltestds");
      out.println("got a DataSource<br>");
      out.println(ds.toString() + "<br>");
      out.println( (ds instanceof org.apache.commons.dbcp.BasicDataSource)
+ "<br>");
      out.println( (ds instanceof
COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource) + "<br>");
      conn = ds.getConnection();   // exception is thrown here
      ....
} catch (Exception e) {
      out.println("Problems: " + e.toString());
}

and finally the end result viewed with a web browser....
new InitialContext
got a DataSource
org.apache.commons.dbcp.BasicDataSource@7200b4
true
false
Problems: java.sql.SQLException: Cannot create JDBC driver of class
'COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource' for connect URL
'//9.17.41.96:50000'

What is weird to me is if you notice the debug statements, I echo out
"ds.toString()" which gives me
org.apache.commons.dbcp.BasicDataSource@some_memory_address.  I think this
might be where at least one of my problems reside.  Seems to me this should
be COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource@some_memory_address - maybe
I need additional information in the server.xml file?!?!

Any ideas/pushes in the right direction are greatly appreciated.  Thanks in
advance.

Andrew D Johnson
IBM Global Services
Enterprise Monitoring Solutions Lab
(303) 924-6951  5-6951 T/L 263-6951
adjohn@us.ibm.com

This is not rocket science - its only suborbital ballistic propulsion
engineering



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Problems with DB2ConnectionPoolDataSource - "Cannot create JDBC driver"

Posted by Fabio Mengue <fa...@ccuec.unicamp.br>.
Hi Andrew,

You are trying to set up a connection pool, right ?

I think you might use something like:

(server.xml)

<Context path="/emsl" docBase="emsl" debug="0" reloadable="true" 
crossContext="true">
  <Resource name="jdbc/emsltestds" auth="Container" type 
"javax.sql.DataSource"/>
        <ResourceParams name="jdbc/emsltestds">
        <parameter>
        <name>factory</name>
        <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
        </parameter>
        <parameter>
                <name>driverClassName</name>
                <value>COM.ibm.db2.jdbc.app.DB2Driver</value>
        </parameter>
        <parameter>
                <name>url</name>
                <value>jdbc:db2:my_database</value>
        </parameter>
        <parameter>
                <name>username</name>
                <value>xxx</value>
        </parameter>
        <parameter>
                <name>password</name>
                <value>xxx</value>
        </parameter>
        <parameter>
        <name>maxIdle</name>
        <value>0</value>
      </parameter>
      <parameter>
        <name>maxActive</name>
        <value>10</value>
      </parameter>
      <parameter>
        <name>maxWait</name>
        <value>10000</value>
      </parameter>
      </ResourceParams>
     </Context>


The URL part is the challenge. I think you may have something like 
jdbc:db2://9.17.41.96:50000/rtmwasdb in it, but I don't know for sure, 
since I use DB2 Connect (client). driverName is not needed.

Your servlet will now print

org.apache.commons.dbcp.PoolableConnection@<instance_number>.

Voila, you have a poolable connection, managed by Jakarta-Commons DBCP. 
I'm using Tomcat 4.1.14 + JDK 1.4.1_01 on linux.

I tried to set a DB2 connection pool for several weeks, a while ago. IBM 
docs only show how to do it using WebSphere. I can't say that I laughed 
a bit when I saw your domain :)

Good luck,

Fabio.

Andrew D Johnson wrote:

>I'm trying to configure Tomcat to use a DB2ConnectionPoolDataSource, but
>I'm experiencing problems which appear to be related to configuration -
>more specifically the datasource I've defined in the server.xml file, and
>the datasource returned from the InitialContext within the code are
>different.  I receive a "Cannot create JDBC driver of class
>'COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource' " exception
>
>Maybe this situation is best described with code.
>
>In server.xml
><Context path="/emsl" docBase="emsl" debug="0" reloadable="true"
>crossContext="true">
><Resource name="jdbc/emsltestds" auth="SERVLET" type
>="javax.sql.DataSource"/>
><ResourceParams name="jdbc/emsltestds">
><parameter>
><name>user</name><value>username</value>
></parameter>
><parameter>
><name>password</name><value>userpassword</value></parameter>
><parameter>
><name>driverClassName</name><value>COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource</value>
></parameter>
><parameter>
><name>driverName</name><value>jdbc:db2:rtmwasdb</value>
></parameter>
><parameter>
><name>url</name><value>//9.17.41.96:50000</value>
></parameter>
></ResourceParams>
></Context>
>
>In web.xml
><resource-ref>
><description>DB2 Connection</description>
><res-ref-name>jdbc/emsltestds</res-ref-name>
><res-type>javax.sql.DataSource</res-type>
><res-auth>Container</res-auth>
></resource-ref>
>
>the code in my servlet
>try {
>      Context jndiCntx = new InitialContext();
>      out.println("new InitialContext<br>");
>      DataSource ds = (DataSource)jndiCntx.lookup
>("java:comp/env/jdbc/emsltestds");
>      out.println("got a DataSource<br>");
>      out.println(ds.toString() + "<br>");
>      out.println( (ds instanceof org.apache.commons.dbcp.BasicDataSource)
>+ "<br>");
>      out.println( (ds instanceof
>COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource) + "<br>");
>      conn = ds.getConnection();   // exception is thrown here
>      ....
>} catch (Exception e) {
>      out.println("Problems: " + e.toString());
>}
>
>and finally the end result viewed with a web browser....
>new InitialContext
>got a DataSource
>org.apache.commons.dbcp.BasicDataSource@7200b4
>true
>false
>Problems: java.sql.SQLException: Cannot create JDBC driver of class
>'COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource' for connect URL
>'//9.17.41.96:50000'
>
>What is weird to me is if you notice the debug statements, I echo out
>"ds.toString()" which gives me
>org.apache.commons.dbcp.BasicDataSource@some_memory_address.  I think this
>might be where at least one of my problems reside.  Seems to me this should
>be COM.ibm.db2.jdbc.DB2ConnectionPoolDataSource@some_memory_address - maybe
>I need additional information in the server.xml file?!?!
>
>Any ideas/pushes in the right direction are greatly appreciated.  Thanks in
>advance.
>
>Andrew D Johnson
>IBM Global Services
>Enterprise Monitoring Solutions Lab
>(303) 924-6951  5-6951 T/L 263-6951
>adjohn@us.ibm.com
>
>This is not rocket science - its only suborbital ballistic propulsion
>engineering
>
>
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>  
>

-- 
Fabio Mengue - Centro de Computacao - Unicamp
fabio@ccuec.unicamp.br       fabio@unicamp.br
"Quem se mata de trabalhar merece mesmo morrer." - Millor



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>