pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Finneid <tfinneid@fcon.no>
To: pgsql-jdbc@postgresql.org
Subject: Connection exceptions
Date: Fri, 19 Jun 2009 12:37:15 +0200 (CEST)
Message-ID: <54338.134.32.140.234.1245407835.squirrel@fcon.no> (raw)


Hi

Anybody got any best practices for how do I deal with connection problems
in JDBC?

I am working on a storage tier where the DAOs can encounter faulty
database connections, either closed or other-wise non functional
connections.
The database connection is pooled with Commons DBCP, and my initial
thought was to reinitialise or restart the pool, if there were any
problems.
But then I realised that the pool can test connections before giving it to
the application, so now moving into muddy waters because I dont know much
about these details.

My original code is something like:

  while (retry > 0) {
    Connection con = ds.getConnection
    if (con==null) {
        dsFactory.restartDS();
        retry--:
        continue;
    }
    try {
       dao.execute();
    } catch (SQLExceptions e) {

    con.close();
  }

Not knowing the details of how the DBCP or the DataSource works in these
situations, make this code prone to problems.

I will continue to investigate, but any feedback about what to look at is
appreciated.

regards

thomas




view thread (4+ messages)  latest in thread

Message-ID: <54338.134.32.140.234.1245407835.squirrel@fcon.no>
Permalink:  ../54338.134.32.140.234.1245407835.squirrel@fcon.no/
Also on:    postgresql.org/message-id/54338.134.32.140.234.1245407835.squirrel@fcon.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: tfinneid@fcon.no
  Subject: Re: Connection exceptions
  In-Reply-To: <54338.134.32.140.234.1245407835.squirrel@fcon.no>
  References: <54338.134.32.140.234.1245407835.squirrel@fcon.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox