From: Andreas <ml@3.141592654.de>
To: pgsql-jdbc@postgresql.org
Subject: Re: keeping Connection alive
Date: Sun, 13 Dec 2009 02:37:44 +0100 (CET)
Message-ID: <21846658.35.1260668264808.JavaMail.root@store1.zcs.ext.wpsrv.net> (raw)
In-Reply-To: <98B3D2B2-9F95-43CA-AA0A-02CD8ACE771B@groupspeak.com>
Hi Jovan,
thanks for your reply!
> On Dec 12, 2009, at 6:43 PM, Andreas Brandl wrote:
> > I'm using a PostgreSQL as backend for a Java application, which may
> idle for quite a while (i.e. hours) and now and then issue a query on
> the backend.
>
> Is this a standard Java application or is it running in a Java EE or
> servlet container?
This is a standard Java application.
> If you're not using an application server, and/or don't need pooling,
> perhaps it would be better to use the regular jdbc api something like
> this:
> Class.forName("org.postgresql.Driver");
> Connection conn = DriverManager.getConnection(jdbcConnUrl, username,
> password);
> // then conn.createStatement , etc.
>
> Then you can call conn.close() and create a new connection when
> necessary.
I did work with a pure Connection before, until I realized things go wrong when application is idle for long time.
In either case, the problem is how to detect whether a Connection is valid or not. As far as I know there is no native mechanism for checking the state. So one approach may be to implement a DataSource which does check (i.e. "SELECT 1") validity before returning the Connection (and reconnect if its not valid, i.e. throwing a SQLException?).
Is there any better way to achieve this? After all this might mean a lot of overhead (checking every time DataSource.getConnection() is called)...
Thanks,
Andreas
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: ml@3.141592654.de
Subject: Re: keeping Connection alive
In-Reply-To: <21846658.35.1260668264808.JavaMail.root@store1.zcs.ext.wpsrv.net>
References: <98B3D2B2-9F95-43CA-AA0A-02CD8ACE771B@groupspeak.com> <21846658.35.1260668264808.JavaMail.root@store1.zcs.ext.wpsrv.net>
* 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