You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by Donald McLean <dm...@gmail.com> on 2008/05/29 17:55:20 UTC

Derby in Tomcat webapps

The new version of our webapp uses Tomcat (and it works like a champ!) but
there are a couple of annoying issues that I would like to resolve:

1. When I unload and then reload the app, the new instance of the app can't
start the database. I have to stop and then start Tomcat.

2. When I try to run a second app that uses Tomcat, it can't start the
database.

I would greatly appreciate some suggestions as to how I should modify my
configuration so that I can resolve these problems.

Thank you,

Donald

Re: Derby in Tomcat webapps

Posted by Donald McLean <dm...@gmail.com>.
Sample code - always the perfect gift.

Thank you, Alan.

On Sat, May 31, 2008 at 3:40 AM, Alan Burlison <Al...@sun.com>
wrote:

> Donald McLean wrote:
>
>  I would greatly appreciate some suggestions as to how I should modify my
>> configuration so that I can resolve these problems.
>>
>
>
> http://auth.opensolaris.org/svn/showfile.svn?path=%2ftrunk%2fAuthDb%2fsrc%2forg%2fopensolaris%2fauth%2fdb%2fDbManager.java&revision=HEAD&name=auth
>

Re: Derby in Tomcat webapps

Posted by Alan Burlison <Al...@sun.com>.
Donald McLean wrote:

> I would greatly appreciate some suggestions as to how I should modify my
> configuration so that I can resolve these problems.

http://auth.opensolaris.org/svn/showfile.svn?path=%2ftrunk%2fAuthDb%2fsrc%2forg%2fopensolaris%2fauth%2fdb%2fDbManager.java&revision=HEAD&name=auth

-- 
Alan Burlison
--

Re: Derby in Tomcat webapps

Posted by Sai Pullabhotla <sa...@jmethods.com>.
I solved this issue in my web app doing the following:

1. Create two JNDI data sources to the same database - one a normal
connection and another one for shutdown (in the JDBC URL, specify
shutdown=true.
2. Create a ServletContextListener and register it with Tomcat in the
web.xml file so you receive notification when the context is
initialized or destroyed.
3. In the destroyed method, get a connection from the DataSource that
was added specifically to shut down the Derby database cleanly.

This has been working great for us so far. Hope this helps to you too.

Regards,
Sai Pullabhotla

On Thu, May 29, 2008 at 10:55 AM, Donald McLean <dm...@gmail.com> wrote:
> The new version of our webapp uses Tomcat (and it works like a champ!) but
> there are a couple of annoying issues that I would like to resolve:
>
> 1. When I unload and then reload the app, the new instance of the app can't
> start the database. I have to stop and then start Tomcat.
>
> 2. When I try to run a second app that uses Tomcat, it can't start the
> database.
>
> I would greatly appreciate some suggestions as to how I should modify my
> configuration so that I can resolve these problems.
>
> Thank you,
>
> Donald
>



-- 
Sai Pullabhotla
Phone: (402) 408-5753
Fax: (402) 408-6861
www.jMethods.com

RE: Derby in Tomcat webapps

Posted by "Gilbert, Clint" <Cl...@childrens.harvard.edu>.
For what it's worth, I had a problem similar to the original poster's.  Upon restarting Tomcat, my embedded Derby DB would occasionally boot read-only, or not at all - a problem on a development server that was bounced frequently.  This was using Hibernate and its built-in connection pooling.  It seemed that the DB was never getting properly shut down.  

I solved the problem by running the Derby network server on my local machine and making connections to that instead of the embedded DB.  That's a lot less slick, however, so I plan to try using a "real" JNDI datasource in the future.


-----Original Message-----
From: Robert J. Carr [mailto:rjcarr@gmail.com]
Sent: Thu 5/29/2008 12:11 PM
To: Derby Discussion
Subject: Re: Derby in Tomcat webapps
 
> 1. When I unload and then reload the app, the new instance of the app can't
> start the database. I have to stop and then start Tomcat.

My application runs in tomcat and I can deploy and undeploy my app and
the database is fine and I'm able to reconnect.  Are you unloading the
database when you undeploy?

> 2. When I try to run a second app that uses Tomcat, it can't start the
> database.

If you are using embedded derby, as far as I know, you can only have
one active connection to it at a time.

You might be able to get around this using JNDI data sources, which I
think ties the connection to tomcat and not to your application.  I
haven't confirmed this, but it is worth a shot if you're not already
doing it (and a better practice as well).

Good luck!




Re: Derby in Tomcat webapps

Posted by Donald McLean <dm...@gmail.com>.
On Thu, May 29, 2008 at 12:11 PM, Robert J. Carr <rj...@gmail.com> wrote:

> > 1. When I unload and then reload the app, the new instance of the app
> can't
> > start the database. I have to stop and then start Tomcat.
>
> My application runs in tomcat and I can deploy and undeploy my app and
> the database is fine and I'm able to reconnect.  Are you unloading the
> database when you undeploy?


Hmmm. Perhaps not. What exactly do you mean by "unloading the database"?


> > 2. When I try to run a second app that uses Tomcat, it can't start the
> > database.
>
>
> If you are using embedded derby, as far as I know, you can only have
> one active connection to it at a time.
>
> You might be able to get around this using JNDI data sources, which I
> think ties the connection to tomcat and not to your application.  I
> haven't confirmed this, but it is worth a shot if you're not already
> doing it (and a better practice as well).
>

My apologies for being unclear. I'm not trying to open a connection to the
same database, I'm trying to open a connection to a different database. I
suspect this is some kind of class loader issue.

Thank you,

Donald

Re: Derby in Tomcat webapps

Posted by Narayanan <V....@Sun.COM>.
Dag H. Wanvik wrote:
> "Robert J. Carr" <rj...@gmail.com> writes:
>
>   
>> If you are using embedded derby, as far as I know, you can only have
>> one active connection to it at a time.
>>     
>
> Just to clarify, embedded Derby supports many JDBC connections, but
> cannot support multiple simultaneous boots. If two different VMs try
> to boot the same enbedded database, the second boot attempt will be
> denied.
>   
I found some links related to tomcat and derby

http://db.apache.org/derby/integrate/DerbyTomcat5512JPetStor.html
www.pintux.it/docs/Derby-Tomcat-en.pdf

not directly related to the discussion but might be helpful to someone
trying to work with the two.

Narayanan

Re: Derby in Tomcat webapps

Posted by "Dag H. Wanvik" <Da...@Sun.COM>.
"Robert J. Carr" <rj...@gmail.com> writes:

> If you are using embedded derby, as far as I know, you can only have
> one active connection to it at a time.

Just to clarify, embedded Derby supports many JDBC connections, but
cannot support multiple simultaneous boots. If two different VMs try
to boot the same enbedded database, the second boot attempt will be
denied.

Re: Derby in Tomcat webapps

Posted by "Robert J. Carr" <rj...@gmail.com>.
> 1. When I unload and then reload the app, the new instance of the app can't
> start the database. I have to stop and then start Tomcat.

My application runs in tomcat and I can deploy and undeploy my app and
the database is fine and I'm able to reconnect.  Are you unloading the
database when you undeploy?

> 2. When I try to run a second app that uses Tomcat, it can't start the
> database.

If you are using embedded derby, as far as I know, you can only have
one active connection to it at a time.

You might be able to get around this using JNDI data sources, which I
think ties the connection to tomcat and not to your application.  I
haven't confirmed this, but it is worth a shot if you're not already
doing it (and a better practice as well).

Good luck!