You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by todd runstein <to...@yahoo.com> on 2004/02/05 23:50:30 UTC

JNDI datasource lost on redeploy

I've set up a JNDI datasource on my test server that
works just fine (Tomcat=5.0.18, JDK=1.4.1, RedHat=8,
M$_SQL=2000).  However, each time I recompile and
redeploy the application, I lose my connection pool,
recieving the "Cannot create JDBC driver of class ''
for connect URL 'null'" error.  I have to restart
Tomcat to get it working again.

This sort of makes sense, since I'm defining the
Resource within a Context in server.xml.  It seems
that I either need to make the resource globally
available to every web app, or move the resource
definition to within my web app.  Unfortunately, I
don't know what to move or where to move it or what
options might work.  Any advice or suggestions?

I'm including all the code used to get the connection
as it stands now.  Again, this currently works up
until I try to redeploy the web app.

My driver jars (there are 3 for MS SQL) are in
$CATALINA_HOME/common/lib

server.xml:
          <Context path="/mfgreports"
docBase="mfgreports" debug="5">
              <Resource
name="datasource.testtrk.circuits"
                auth="Container"
                type="javax.sql.DataSource" />
              <ResourceParams
name="datasource.testtrk.circuits">
                <parameter>
                        <name>factory</name>
                       
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
                </parameter>
                .....
                <parameter>
                        <name>driverClassName</name>
                       
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
                </parameter>
                <parameter>
                        <name>url</name>
                       
<value>jdbc:microsoft:sqlserver://testtrk:1433;databasename=Circuits</value>
                </parameter>

              </ResourceParams>
          </Context>


web.xml:
	<resource-ref>	
	
<res-ref-name>datasource.testtrk.circuits</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>


Code used to get connection:
public class JNDIConnection {

	public static Connection getConnection(String
datasource) 
		throws NamingException, SQLException{
			Context ctx = new InitialContext();
//This syntax is a bit different than the docs show,
but it appears to be working
			DataSource ds =
(DataSource)ctx.lookup("java:comp/env/"+datasource); 
			return ds.getConnection();
	}
}

Thanks again!

=====
The only "dumb question" is the one you were too afraid to ask.
________________________________________

Check out RouteRuler - Free software for runners, cyclists, walkers, etc.
http://routeruler.sourceforge.net
________________________________________

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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


Re: JNDI datasource lost on redeploy - solved

Posted by todd runstein <to...@yahoo.com>.
Got it!  

The reference to conf/Catalina/localhost helped me
search the archives to find a message from Derek Mahar
on 12/15/03 named "JNDI Issue with
GlobalNamingResources & DefaultContext Solved".  In
it, Derek suggests placing the context file in
META-INF/context.xml.  So I pulled out the <Context>
node from server.xml, pasted that in a new file named
context.xml, had ant put that file in META-INF while
building the war file and viola - success!  

Thanks Josh and Derek!


--- Josh Rehman <jr...@citysearch.com> wrote:
> Can't solve your problem, but two things:first, try
> posting a war that 
> reproduces the bug. In this case it might be an ant
> script that 
> undeploys and redeploys a trivial war. Second, it
> has recently come to 
> light that you aren't supposed to mess with
> server.xml Contexts anymore 
> with TC5. You should modify the context xml fragment
> in 
> conf/Catalina/localhost/ (or something like that).
> The fragment will be 
> named after the context.
> 
> todd runstein wrote:
> > problems..
> 
> -- 
> Josh Rehman
> citysearch.com
> 213.739.3559
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> tomcat-user-help@jakarta.apache.org
> 

=====
The only "dumb question" is the one you were too afraid to ask.
________________________________________

Check out RouteRuler - Free software for runners, cyclists, walkers, etc.
http://routeruler.sourceforge.net
________________________________________

__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html

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


Re: JNDI datasource lost on redeploy

Posted by Josh Rehman <jr...@citysearch.com>.
Can't solve your problem, but two things:first, try posting a war that 
reproduces the bug. In this case it might be an ant script that 
undeploys and redeploys a trivial war. Second, it has recently come to 
light that you aren't supposed to mess with server.xml Contexts anymore 
with TC5. You should modify the context xml fragment in 
conf/Catalina/localhost/ (or something like that). The fragment will be 
named after the context.

todd runstein wrote:
> problems..

-- 
Josh Rehman
citysearch.com
213.739.3559


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