Skip site navigation (1) Skip section navigation (2)

Re: an efficient way of checking if the connection to a db

From: Kris Jurka <books(at)ejurka(dot)com>
To: Assad Jarrahian <jarraa(at)gmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: an efficient way of checking if the connection to a db
Date: 2005-12-15 21:42:14
Message-ID: Pine.BSO.4.61.0512151635390.17948@leary.csoft.net (view raw or flat)
Thread:
Lists: pgsql-jdbc

On Thu, 15 Dec 2005, Assad Jarrahian wrote:

>   Trying to check if a connection is actually open every time I perform 
> an operation (if not, I want to reopen it and perform that operation). 
> isClosed()  is no good, as in, it only guarantees true if close() was
> actually called on it.
>
> The documentation says, the only real way is to actually call an sql
> statement on it. That seems inefficient. Is there any other way that is
> recommended?

The overhead of a query like "SELECT 1" can't be that much.  If this is a 
concern you could add some code to the V3 QueryExecutor that issued just a 
Sync message which would tell you if the connection was still good.  Then 
you'd have to call a pg specific interface to access this functionality.

Getting the official driver to provide this interface would require 
demonstrating that the overhead of SELECT 1 is significantly higher than 
Sync.

Kris Jurka

In response to

Responses

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2005-12-15 22:13:04
Subject: Re: CallableStatements: index starts at 2
Previous:From: Paul ThomasDate: 2005-12-15 21:38:11
Subject: Re: an efficient way of checking if the connection to a db is actually open

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group