You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Craig Dunn <li...@codenation.net> on 2007/12/06 12:40:16 UTC

Null datasource trying to connect to JNDI connection.

Hi, 
 
I have an issue connecting to MSSQL 2000 from Tomcat 6.0 (Linux) using
JNDI. When I try and lookup the DataSource object it comes back as
null.... I have configured; 
 
In my server.xml: 
 
<Context path="/myApp" DocBase="myApp" debug="0" reloadable="false"
crossContext="true"> 
<Resource type="javax.sql.DataSource" name="jdbc/myDB"  
auth="Container"
factory="org.apache.commons.dbcp.BasicDataSourceFactory" 
maxActive="100" maxIdle="30" maxWait="10000" username="user"
password="pass" 
driverClassName="net.sourceforge.jtds.jdbc.Driver" 
removeAbandonded="true" logAbandoned="true" 
url="jdbc:jtds:sqlserver://xx.xx.xx.xx:XXXX/myDB"/> 
</Context> 
 
The class calling the data source does so like this; 
 
Context initCtx = new InitialContext(); 
Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
DataSource ds = (DataSource)envCtx.lookup("jdbc/myDB"); 
 
This does not throw any exception, however, ds is null and no physical
connections are made to the database. I would appreciate any advise on
this, its driving me insane. 
 
Also, I have put the following jar's into $CATALINA_HOME/lib on the
advice of other threads; 
commons-pool-1.3.jar 
commons-dbcp-1.2.2.jar 
jtds-1.2.jar 
 
Normal jTDS connections to the same database work fine, so it's nothing
as trivial as a firewall issue. 
 
Thanks in advance 
Craig 
 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Null datasource trying to connect to JNDI connection.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Mark Shifman [mailto:mark.shifman@yale.edu] 
> Subject: Re: Null datasource trying to connect to JNDI connection.
> 
> What would you do if you wanted to add a different version of 
> DBCP, ie Commons DBCP 1.3-SNAPSHOT?
> Would you put the jar in $CATALINA_HOME/lib and then use the factory 
> attribrute?

I think so, but I've never done it.  I don't know what else might have
to be tweaked.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Null datasource trying to connect to JNDI connection.

Posted by Mark Shifman <ma...@yale.edu>.
What would you do if you wanted to add a different version of DBCP, ie 
Commons DBCP 1.3-SNAPSHOT?
Would you put the jar in $CATALINA_HOME/lib and then use the factory 
attribrute?
mas

Caldarale, Charles R wrote:
>> From: Craig Dunn [mailto:lists@codenation.net] 
>> Subject: Null datasource trying to connect to JNDI connection.
>>
>> In my server.xml: 
>>     
>
> The usual comment: don't put <Context> elements in server.xml; doc
> reference:
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html
>
>   
>> factory="org.apache.commons.dbcp.BasicDataSourceFactory" 
>>     
>
> Did you see a factory attribute in any of the Tomcat doc for JDBC
> DataSources?
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.h
> tml
>
>   
>> Context initCtx = new InitialContext(); 
>> Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
>> DataSource ds = (DataSource)envCtx.lookup("jdbc/myDB"); 
>>     
>
> Did you follow the above Tomcat doc and put a <resource-ref> in your
> WEB-INF/web.xml file?
>
>   
>> Also, I have put the following jar's into $CATALINA_HOME/lib on the
>> advice of other threads; 
>> commons-pool-1.3.jar 
>> commons-dbcp-1.2.2.jar 
>>     
>
> Read the Tomcat doc first, then use "other threads" for clarification,
> if needed.  You won't see any mention of adding the above jars to
> Tomcat's lib directory, since Tomcat already has its own versions.
>
>   
>> jtds-1.2.jar 
>>     
>
> That one you need.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   


-- 
 Mark Shifman MD. Ph.D.
 Yale Center for Medical Informatics
 Phone (203)737-5219
 mark.shifman@yale.edu


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Null datasource trying to connect to JNDI connection.

Posted by Craig Dunn <li...@codenation.net>.
> Any ideas on how to trace whats going on?  There are still no exceptions 
> being thrown.


Sorry, I've figured that part out now - thanks for your help.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Null datasource trying to connect to JNDI connection.

Posted by Craig Dunn <li...@codenation.net>.
> Did you see a factory attribute in any of the Tomcat doc for JDBC
> DataSources?
> http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.h
> tml

OK, Thanks for that - I've removed the Factory setting, placed 
everything where it is recommended, and yes, I did already have a 
web.xml entry for it - It's now opening up physical connections to the 
database, which is good... However, the following code still returns a 
null DataSource object...

> 
>> Context initCtx = new InitialContext(); 
>> Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
>> DataSource ds = (DataSource)envCtx.lookup("jdbc/myDB"); 

Any ideas on how to trace whats going on?  There are still no exceptions 
being thrown.

Thanks.
Craig


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Null datasource trying to connect to JNDI connection.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Craig Dunn [mailto:lists@codenation.net] 
> Subject: Null datasource trying to connect to JNDI connection.
> 
> In my server.xml: 

The usual comment: don't put <Context> elements in server.xml; doc
reference:
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

> factory="org.apache.commons.dbcp.BasicDataSourceFactory" 

Did you see a factory attribute in any of the Tomcat doc for JDBC
DataSources?
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.h
tml

> Context initCtx = new InitialContext(); 
> Context envCtx = (Context) initCtx.lookup("java:comp/env"); 
> DataSource ds = (DataSource)envCtx.lookup("jdbc/myDB"); 

Did you follow the above Tomcat doc and put a <resource-ref> in your
WEB-INF/web.xml file?

> Also, I have put the following jar's into $CATALINA_HOME/lib on the
> advice of other threads; 
> commons-pool-1.3.jar 
> commons-dbcp-1.2.2.jar 

Read the Tomcat doc first, then use "other threads" for clarification,
if needed.  You won't see any mention of adding the above jars to
Tomcat's lib directory, since Tomcat already has its own versions.

> jtds-1.2.jar 

That one you need.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org