db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Susan L. Cline" <home4...@pacbell.net>
Subject Re: Using Apache DBCP and Tomcat with Derby - database shutdown?
Date Thu, 07 Sep 2006 22:49:55 GMT
--- Daniel John Debrunner <djd@apache.org> wrote:

> home4slc@pacbell.net wrote:
> > Hi Deepa,
> >  
> > Thanks a lot for your help.  That worked like a charm.
> >  
> > So I have now changed my code to this:
> >  
> >    ((EmbeddedDataSource)ds).setShutdownDatabase("shutdown");
> >    ((EmbeddedDataSource)ds).getConnection();
> Just a couple of warnings with this code:
>    1) This affects the datasource for every application or thread that
> is using it.

That makes sense, in this case this is what I want.  The method that this code
is wrapped in is called when Tomcat is shutdown.

>    2) Some J2EE app servers will wrap the database's DataSource
> implementation in their own, meaning the cases will fail.

Sorry, not sure what you mean 'the cases will fail'?  However, as I mentioned
in my next email, it turns out this does not work because of the way I have Tomcat
server.xml set up.  I have it configured to use the Apache DBCP connection pool
class instead of the Derby EmbeddedDataSource class.  But I am pointing to the
Derby EmbeddedDriver class as the driver class name.  It seems like if I want to
use the Apache DBCP connection pooling I have to use the Derby EmbeddedDriver because
one of the parameters DBCP requires is a URL parameter, which leads me back to my
original question.

> Another way is to have another Derby data source setup in the
> configuration that has the shutdownDatabase property set to "shutdown".
> Then you would do:
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("java:comp/env");
> DataSource ds = (DataSource)
>   envCtx.lookup("jdbc/EmployeeDB_shutdown");
> try {
>   ds.getConnection();
> } catch (SQLExcepion sqle) {
> }

Good suggestion, thanks.

> Dan.

View raw message