Hi, 
despite the fact that I did get some responses (and a thread hijack), I
am still trying to solve this. Any help appreciated.

I am trying to get DBCP connection pooling to work with Tomcat 4.1.24
and DB2 8.X. I can connect directly, but whenever I try to use DBCP, I
receive a "Cannot load driver class 'null'" error. The DB2 and JNDI jar
files are located in <tomcat-root>\common\lib.

This code snippet works:
...
String url = "jdbc:db2://myserver:50000/mydb";
String user = "test";
String pass = "password"; Class.forName("com.ibm.db2.jcc.DB2Driver");
Connection conn = DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
ResultSet myRs = stmt.executeQuery("select * from myTable"); ...

This leads me to believe that:
a) My driver is fine and jar file location is ok
b) My login credentials are fine
I use the same driver and connection info in my DBCP config. 

-------------------------------------------
Now when I try to use DBCP, this code snippet does NOT work. ... Context
jndiCtx = new InitialContext(); Context ctx = (Context)
jndiCtx.lookup("java:comp/env"); DataSource ds = (DataSource)
ctx.lookup("jdbc/mydb"); Connection conn = ds.getConnection(); Statement
stmt = conn.createStatement(); ResultSet myRs =
stmt.executeQuery("select * from myTable"); ...

Tomcat does not throw any errors at startup in any logs and when I
execute the above code, the DataSource retrieved (ds) is not null and a
getClassName() call reveals a generic commons DataSource object.
However, once it gets to the getConnection() method, the evil "Cannot
load driver class 'null'" error occurs.

I tried messing around with the JNDI entries to prove that was OK, and
as expected I get a naming error if I put a wrong value. This tells me
that the "lookup" portion works, yes?

Here are the relevant server.xml and the web.xml entries:

------------------------------------------------------
server.xml (note: I also tried it without the factory param)
------------------------------------------------------
...
<Context...>
   <Resource name="jdbc/mydb" scope="Shareable"
type="javax.sql.DataSource" auth="Container" />

  <Resourceparams name="jdbc/mydb">
   <parameter>
   <name>factory</name>
   <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
   </parameter>
<parameter>
   <name>username</name>
   <value>test</value>
   </parameter>
<parameter>
   <name>password</name>
   <value>password</value>
   </parameter>
<parameter>
   <name>driverClassName</name>
   <value>com.ibm.db2.jcc.DB2Driver</value>
   </parameter>
<parameter>
   <name>url</name>
   <value>jdbc:db2://myserver:50000/mydb</value>
   </parameter>
</Resourceparams>
</Context>

------------------------------------------------------
web.xml
------------------------------------------------------
...
<resource-ref>
  <resource-ref-name>jdbc/mydb<resource-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
</resource-ref>


So, that is pretty much it. I have consulted 2 books, countless
websites, and would appreciate any help.

Thanks

JW



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

Reply via email to