Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detecting Failed JDBC Connection

21 views
Skip to first unread message

Scott Jones

unread,
Apr 2, 2002, 3:01:43 PM4/2/02
to
Hello,

I'm in the midst of implementing a redundant replicated database. I'd
like our application to seamlessly detect that one of our databases is
down, and switch over to the other one.

At the moment, I have two Connection pools (I've been using the James
Cooper's JDBCPool to create these pools -- see
http://bitmechanic.com/projects/jdbcpool). Anyways, I'd like to be
able to detect when a connection has failed.

I've been playing with one database on one machine and the replicated
database on another. Then I've been pulling the network cable out of
the replicated database machine, and trying to run an update on our
application. It is able to obtain a connection from the connection
pool, and then merrily proceeds to try to run the update. When the
connection pool manager detects a connection that's been out too long,
it tries to close it, and then I get a

COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] CLI0116E Invalid
transaction state. SQLSTATE=25000
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.throw_SQLException(SQLExceptionGenerator.java:174)
at COM.ibm.db2.jdbc.app.SQLExceptionGenerator.check_return_code(SQLExceptionGenerator.java:431)
at COM.ibm.db2.jdbc.app.DB2Connection.close2(DB2Connection.java:694)
at COM.ibm.db2.jdbc.app.DB2Connection.close(DB2Connection.java:667)
at com.bitmechanic.sql.PooledConnection.run(PooledConnection.java:91)
at com.bitmechanic.util.JavaAlarm.run(JavaAlarm.java:42)

Is there a way for me to detect that a connection is really broken
without actually trying to use it?

Thanks!

-Scott

Dirk "db2scout" Wollscheid

unread,
Apr 2, 2002, 4:03:15 PM4/2/02
to

"Scott Jones" <sc...@on-sitemanager.com> wrote in message
news:fa40192c.0204...@posting.google.com...

You could try java.sql.Connection.isClosed() , but I'm not sure if it checks
if the database server is up and running. It's worth a try.

Dirk


Scott Jones

unread,
Apr 3, 2002, 5:47:13 PM4/3/02
to
> You could try java.sql.Connection.isClosed() , but I'm not sure if it checks
> if the database server is up and running. It's worth a try.

Yeah, I tried that, but it returns false even if I've unplugged the
machine (from the network)!!! :( However, if I shut down db2 gently
with db2stop or even just use "db2 force applications all" then things
work ok...

Right now, I'm trying to get my code that opens new connections to
"time-out" after trying to open a connection to a dead machine for a
while...

Thanks for the suggestion!

-Scott

Jerry Stuckle

unread,
Apr 3, 2002, 11:18:04 PM4/3/02
to
Scott,

The difference is - when you unplug the cable, you have nothing to give
a negative response. So the requestor just waits for something to
respond.

If DB2 is shut down but the machine is otherwise running, it's
networking can provide a negative response to the requestor.

It should time out eventually - how long could be several minutes,
depending on the timeout values and number of retries.

--
====================================
To reply, delete the 'x' from my email

Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
====================================

0 new messages