You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rainer Frey <ra...@inxmail.de> on 2009/11/16 14:24:37 UTC

Webapp reload and DriverManager in Tomcat 6.0 trunk

Hi,

I found a problem when using DriverManager.getConnection() with a build from 
current 6.0 SVN (this morning). Basically I have a Servlet that's loaded on 
startup and does following in its init() method:

try
{
	Class.forName( driver );
}
catch( ClassNotFoundException x )
{
	log( x.toString(), x );
}
Connection con = null;
try
{
	con = DriverManager.getConnection( url, user, pass );
	log( "connection established: " + con.toString() );
}
catch( SQLException x )
{
	log( x.toString(), x );
	throw new ServletException( x.toString(), x );
}

After starting Tomcat, I get the following expected output:

Nov 16, 2009 1:56:11 PM org.apache.catalina.core.ApplicationContext log
INFO: DBTestServlet: connection established: 
org.postgresql.jdbc4.Jdbc4Connection@17ec9f7
Nov 16, 2009 1:56:12 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()

But when reloading the context (by touching web.xml), I get the following 
exception:

Nov 16, 2009 1:56:32 PM org.apache.catalina.core.ApplicationContext log
SEVERE: DBTestServlet: java.sql.SQLException: No suitable driver found for 
jdbc:postgresql://127.0.0.1/inxmail
java.sql.SQLException: No suitable driver found for 
jdbc:postgresql://127.0.0.1/inxmail
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at com.inxmail.test.DBTestServlet.init(DBTestServlet.java:49)
        at javax.servlet.GenericServlet.init(GenericServlet.java:212)
        at 
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
        at 
org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
        at 
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
        at 
org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
        at 
org.apache.catalina.startup.HostConfig.checkResources(HostConfig.java:1192)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1290)
        at 
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:296)
        at 
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
        at 
org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1337)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
        at java.lang.Thread.run(Thread.java:619)
Nov 16, 2009 1:56:32 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /testdb threw load() exception

I tested with Java 6 (1.6.0_17) and JDBC 3 and 4 Drivers for Oracle 
(ojdbc1.4.jar from Oracle 10, ojdbc6 from Oracle 11) as well as PostgreSQL.

Everything works fine with Tomcat 6.0.20.

The error originally occured in a much more complicated application with a 
home-grown DB connection pool, but the servlet I mentioned above exhibits 
this behavior. For anyone willing to test: here is a  .war file with this 
servlet, please edit web.xml to fill in your DB connection details.
http://download.inxmail.com/data/user/rfy/testdb.war

I'm testing our application for compatibility with the upcoming 6.0.21 
release, so I'd be grateful if s.o. could try to verify whether this is a 
Bug, so it has a chance to be addressed before 6.0.21

Thanks, and sorry for the lengthy message
Rainer




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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Rainer Frey <ra...@inxmail.de>.
On Monday 16 November 2009 14:24:37 Rainer Frey wrote:
> Hi,
>
> I found a problem when using DriverManager.getConnection() with a build
> from current 6.0 SVN 

[...]

As requested, added a bugzilla entry:
https://issues.apache.org/bugzilla/show_bug.cgi?id=48214

Rainer

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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Rainer Frey <ra...@inxmail.de>.
On Monday 16 November 2009 14:24:37 Rainer Frey wrote:
> Hi,

> The error originally occured in a much more complicated application with a
> home-grown DB connection pool, but the servlet I mentioned above exhibits
> this behavior. For anyone willing to test: here is a  .war file with this
> servlet, please edit web.xml to fill in your DB connection details.
> http://download.inxmail.com/data/user/rfy/testdb.war

As requested, I changed the demo app to use a META-INF/context.xml, so please 
download again from http://download.inxmail.com/data/user/rfy/testdb.war and, 
after deploying, edit conf/<engine>/<host>/testdb.xml

I also uploaded the changed servlet source to 
http://download.inxmail.de/data/user/rfy/DBTestServlet.java

Thanks for any help
Rainer

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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by "Rainer Frey (Inxmail GmbH)" <ra...@inxmail.de>.
On Monday 16 November 2009 15:00:32 Pid wrote:
> On 16/11/2009 13:54, Rainer Frey wrote:
> > I forgot a very important information: the JDBC driver is in tomcat/lib
> > because our server usually runs several instances of the same webapp, and
> > the customers have to add the JDBC driver themselves because we can't
> > supply them due to licensing issues.
>
> In your test servlet, can you add some logging to see which classloader
> the successfully loaded driver class has, the first time you start the app?

It is (as expected), the tomcat common classloader, also at reload.

INFO: DBTestServlet: Class org.postgresql.Driver loaded by 
org.apache.catalina.loader.StandardClassLoader@184ec44
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Tomcat start

Nov 16, 2009 3:12:11 PM org.apache.catalina.core.ApplicationContext log
INFO: DBTestServlet: connection established: 
org.postgresql.jdbc4.Jdbc4Connection@121177e
Nov 16, 2009 3:12:11 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Nov 16, 2009 3:12:11 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Nov 16, 2009 3:12:41 PM org.apache.catalina.core.ApplicationContext log
INFO: DBTestServlet: Class org.postgresql.Driver loaded by 
org.apache.catalina.loader.StandardClassLoader@184ec44
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Context reload

Nov 16, 2009 3:12:41 PM org.apache.catalina.core.ApplicationContext log
SEVERE: DBTestServlet: java.sql.SQLException: No suitable driver found for 
jdbc:postgresql://127.0.0.1/inxmail
java.sql.SQLException: No suitable driver found for 
jdbc:postgresql://127.0.0.1/inxmail
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:185)
        at com.inxmail.test.DBTestServlet.init(DBTestServlet.java:50)
        at javax.servlet.GenericServlet.init(GenericServlet.java:212)
 

I uploaded the webapp again with this logging, and also uploaded the full 
servlet source file to 
http://download.inxmail.de/data/user/rfy/DBTestServlet.java

Rainer

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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Pid <pi...@pidster.com>.
On 16/11/2009 13:54, Rainer Frey wrote:
> On Monday 16 November 2009 14:24:37 Rainer Frey wrote:
>> Hi,
>>
>> I found a problem when using DriverManager.getConnection() with a build
>> from current 6.0 SVN (this morning).
> [...]
>> Everything works fine with Tomcat 6.0.20.
>
> I forgot a very important information: the JDBC driver is in tomcat/lib
> because our server usually runs several instances of the same webapp, and the
> customers have to add the JDBC driver themselves because we can't supply them
> due to licensing issues.

In your test servlet, can you add some logging to see which classloader 
the successfully loaded driver class has, the first time you start the app?


p



> Rainer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Rainer Frey <ra...@inxmail.de>.
On Monday 16 November 2009 14:24:37 Rainer Frey wrote:
> Hi,
>
> I found a problem when using DriverManager.getConnection() with a build
> from current 6.0 SVN (this morning). 
[...]
> Everything works fine with Tomcat 6.0.20.

I forgot a very important information: the JDBC driver is in tomcat/lib  
because our server usually runs several instances of the same webapp, and the 
customers have to add the JDBC driver themselves because we can't supply them 
due to licensing issues.

Rainer 

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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Rainer Frey <ra...@inxmail.de>.
On Monday 16 November 2009 14:32:41 Mikolaj Rydzewski wrote:
> Rainer Frey wrote:
> > I found a problem when using DriverManager.getConnection() with a build
> > from current 6.0 SVN (this morning). Basically I have a Servlet that's
> > loaded on startup and does following in its init() method:
>
> You should really use JNDI to obtain DataSource.

That's generally right. This is about a legcy application, and I want to make 
sure it still works after a minor version update of tomcat. So lets please 
leave such discussion out of this thread.

Rainer

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


Re: Webapp reload and DriverManager in Tomcat 6.0 trunk

Posted by Mikolaj Rydzewski <mi...@ceti.pl>.
Rainer Frey wrote:
> I found a problem when using DriverManager.getConnection() with a build from 
> current 6.0 SVN (this morning). Basically I have a Servlet that's loaded on 
> startup and does following in its init() method:
>   
You should really use JNDI to obtain DataSource.

-- 
Mikolaj Rydzewski <mi...@ceti.pl>


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