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 Henrik Frisk <fr...@gmail.com> on 2008/02/11 22:24:17 UTC
Shutdown of embedded Derby server throws an SQLException?
Hi,
I'm just starting to familiarize myself with the Derby Java API and I keep
getting an Exception when I'm trying to shut down an embedded server using
the following call:
DriverManager.getConnection("jdbc:derby:;shutdown=true");
Now, I was just looking at the SimpleNetworkServerSample demo that comes
with the db-derby download and saw he following:
try
{
// shutdown Derby Network Server
DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch(SQLException se)
{
//ignore se
}
The comment //ignore se made me think maybe it's normal it throws an
Exception. If not, what would be the right way to shut down the server? I'm
starting the server with
System.setProperty("derby.drda.startNetworkServer","true");
and run it with the embedded driver. The db will run strictly on localhost
and I'm in control of the clients connecting to it.
Any hints would be greatly appreciated,
Henrik
Re: Shutdown of embedded Derby server throws an SQLException?
Posted by Bryan Pendleton <bp...@amberpoint.com>.
> keep getting an Exception when I'm trying to shut down an embedded
> server using the following call:
Yes, it's expected that you will get an exception when shutting
down the server; see
http://db.apache.org/derby/docs/10.3/devguide/tdevdvlp20349.html
You should print out the exception that you are receiving to
confirm that it's the expected shutdown exception. Here's some
info on printing out the exception information to view it:
http://wiki.apache.org/db-derby/UnwindExceptionChain
thanks,
bryan
Re: Shutdown of embedded Derby server throws an SQLException?
Posted by bruehlicke <br...@gmail.com>.
This is "as designed". I found other places where the usual way of coding
this is like
try
{
// Now try to disconnect
_connection.close();
_connection = null;
_logger.info("Closed connection");
/*
In embedded mode, an application should shut down Derby.
If the application fails to shut down Derby explicitly,
the Derby does not perform a checkpoint when the JVM shuts
down, which means
that the next connection will be slower.
Explicitly shutting down Derby with the URL is preferred.
This style of shutdown will always throw an "exception".
*/
boolean gotSQLExc = false;
try
{
DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch(SQLException se)
{
gotSQLExc = true;
}
if(!gotSQLExc)
{
_logger.fine("Database did not shut down normally");
}
else
{
_logger.fine("Database shut down normally");
}
}
catch (Throwable e)
{
_logger.fine("exception thrown:"+e.getMessage());
e.printStackTrace();
}
On Feb 11, 2008 3:24 PM, Henrik Frisk <fr...@gmail.com> wrote:
> Hi,
>
> I'm just starting to familiarize myself with the Derby Java API and I keep
> getting an Exception when I'm trying to shut down an embedded server using
> the following call:
>
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
>
> Now, I was just looking at the SimpleNetworkServerSample demo that comes
> with the db-derby download and saw he following:
>
> try
> {
> // shutdown Derby Network Server
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
> }
> catch(SQLException se)
> {
> //ignore se
> }
>
> The comment //ignore se made me think maybe it's normal it throws an
> Exception. If not, what would be the right way to shut down the server? I'm
> starting the server with
>
> System.setProperty("derby.drda.startNetworkServer","true");
>
> and run it with the embedded driver. The db will run strictly on localhost
> and I'm in control of the clients connecting to it.
>
> Any hints would be greatly appreciated,
>
> Henrik
>
Re: Shutdown of embedded Derby server throws an SQLException?
Posted by Henrik Frisk <fr...@gmail.com>.
> The WwdEmbedded.java program that is part of the self-study tutorial in
> Getting Started with Derby
> (http://db.apache.org/derby/docs/dev/getstart/, accessible from
> http://db.apache.org/derby/manuals/index.html) catches the exception
> that is thrown when shutdown is successful and reports whether the
> shutdown was normal or not. This might be helpful.
>
> Kim Haase
Hi all,
Thanks for the help. I'll take a look at the WwdEmbedded.java example
above. To the developers I'd like to say you've done a great job.
Thank you!
best,
Henrik
Re: Shutdown of embedded Derby server throws an SQLException?
Posted by Kim Haase <Ca...@Sun.COM>.
The WwdEmbedded.java program that is part of the self-study tutorial in
Getting Started with Derby
(http://db.apache.org/derby/docs/dev/getstart/, accessible from
http://db.apache.org/derby/manuals/index.html) catches the exception
that is thrown when shutdown is successful and reports whether the
shutdown was normal or not. This might be helpful.
Kim Haase
Jim Newsham wrote:
>
>
> This is the normal behavior, which is admittedly a little quirky. I
> suspect the rationale is that the method must either return a valid
> connection, or throw an exception, and in this case only the latter is
> possible. Personally, I’d rather have a utility method for shutting
> Derby down, though one can easily write that using the current
> getConnection() facility. However, one flaw that I see is that it
> doesn’t seem possible to detect when shutdown fails.
>
>
>
> Jim
>
>
>
> ------------------------------------------------------------------------
>
> *From:* Henrik Frisk [mailto:frisk.h@gmail.com]
> *Sent:* Monday, February 11, 2008 11:24 AM
> *To:* derby-user@db.apache.org
> *Subject:* Shutdown of embedded Derby server throws an SQLException?
>
>
>
> Hi,
>
> I'm just starting to familiarize myself with the Derby Java API and I
> keep getting an Exception when I'm trying to shut down an embedded
> server using the following call:
>
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
>
> Now, I was just looking at the SimpleNetworkServerSample demo that comes
> with the db-derby download and saw he following:
>
> try
> {
> // shutdown Derby Network Server
> DriverManager.getConnection("jdbc:derby:;shutdown=true");
> }
> catch(SQLException se)
> {
> //ignore se
> }
>
> The comment //ignore se made me think maybe it's normal it throws an
> Exception. If not, what would be the right way to shut down the server?
> I'm starting the server with
>
> System.setProperty("derby.drda.startNetworkServer","true");
>
> and run it with the embedded driver. The db will run strictly on
> localhost and I'm in control of the clients connecting to it.
>
> Any hints would be greatly appreciated,
>
> Henrik
>
RE: Shutdown of embedded Derby server throws an SQLException?
Posted by Jim Newsham <jn...@referentia.com>.
This is the normal behavior, which is admittedly a little quirky. I suspect
the rationale is that the method must either return a valid connection, or
throw an exception, and in this case only the latter is possible.
Personally, I'd rather have a utility method for shutting Derby down, though
one can easily write that using the current getConnection() facility.
However, one flaw that I see is that it doesn't seem possible to detect when
shutdown fails.
Jim
_____
From: Henrik Frisk [mailto:frisk.h@gmail.com]
Sent: Monday, February 11, 2008 11:24 AM
To: derby-user@db.apache.org
Subject: Shutdown of embedded Derby server throws an SQLException?
Hi,
I'm just starting to familiarize myself with the Derby Java API and I keep
getting an Exception when I'm trying to shut down an embedded server using
the following call:
DriverManager.getConnection("jdbc:derby:;shutdown=true");
Now, I was just looking at the SimpleNetworkServerSample demo that comes
with the db-derby download and saw he following:
try
{
// shutdown Derby Network Server
DriverManager.getConnection("jdbc:derby:;shutdown=true");
}
catch(SQLException se)
{
//ignore se
}
The comment //ignore se made me think maybe it's normal it throws an
Exception. If not, what would be the right way to shut down the server? I'm
starting the server with
System.setProperty("derby.drda.startNetworkServer","true");
and run it with the embedded driver. The db will run strictly on localhost
and I'm in control of the clients connecting to it.
Any hints would be greatly appreciated,
Henrik