You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by forward <fo...@mail.thesmithconnection.net> on 2003/05/08 19:48:01 UTC

getConnection() returns null when attempting to use Connection Pool

Greetings all. I've read the posts, yet i still can't solve my problem. I'm using java web services developer pack 1.1 (jwsdp1.1) and its embedded tomcat on winXP. The resource listings below all appear within a specific web context, not within the globals.

Here's the resource listing from the server.xml file:

<Resource name="jdbc/OraCore" auth="Container"
					type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/OraCore">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>			
<name>url</name>
<value>jdbc:oracle:thin:@dev1:1521:db1</value>
</parameter>
<parameter>
<name>user</name>
<value>myuser</value>
</parameter>
<parameter>
<name>password</name>
<value>mypass</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>20</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>10</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>-1</value>
</parameter>
<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>
<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>
<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>

</ResourceParams>

My invocation looks like this:

if(cn==null) {

	try{
	Context initCtx = new InitialContext();
	Context envCtx = (Context) initCtx.lookup("java:comp/env");
	DataSource ds = (DataSource)
	  envCtx.lookup("jdbc/OraCore");
	DataSource dsProd = (DataSource)
	  envCtx.lookup("jdbc/OraProd");

	cat.debug("Connecting to OraCore...");
	if(ds==null){
		cat.debug("ds is null");
	}else{
		cat.debug("ds is " + ds);
	}
	cat.debug("cn = " + cn);
	cn = ds.getConnection();
	cat.debug("cn = " + cn);
	cat.debug("Connected.");

	cat.debug("Connecting to OraProd...");
	cnProd = dsProd.getConnection();
	cat.debug("Connected.");

When this happens, the debug("ds is....") prints out somethign like this, which is expected: ds is org.apache.commons.dbcp.BasicDataSource@1efe475

then, the debug("cn = ") prints null, which is expected.

However, the getConnection() method then returns a null value, and thus I never even make it to the next debug("cn=...") statement because I get a NullPointerException.

I'm having trouble figuring out why this is returning null.

Also, this is interesting: If I use the most basic jndi resource information (see below), then I get a datasource connection which appears indeed to be a database pool connection: 
debug: ds is org.apache.commons.dbcp.PoolingDataSource@8f2ca6

**jndi resource**
<Resource name="jdbc/OraCore" auth="Container"
type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/OraCore">
<parameter>
<name>user</name>
<value>myuser</value>
</parameter>
<parameter>
<name>password</name>
<value>mypass</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>oracle.jdbc.driver.OracleDriver</value>
</parameter>
<parameter>		 		 								
<name>driverName</name>
<value>jdbc:oracle:thin:@dev1:1521:db1</value>
</parameter>
</ResourceParams>

** debug statement when using this resource **

So does this mean that even though I'm not using the jndi resource invocation that the docs call for if I want a database connection pool, that I'm still in fact using a connection pool?

Thanks for any guidance.

-M


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