From: Heikki Linnakangas <heikki@enterprisedb.com>
To: James Im <im-james@hotmail.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: how to continue using a connection after an error with autocommit=false
Date: Tue, 20 Feb 2007 10:50:50 +0000
Message-ID: <45DAD28A.2010907@enterprisedb.com> (raw)
In-Reply-To: <BAY7-F2720A1254B9177F763D58796890@phx.gbl>
References: <BAY7-F2720A1254B9177F763D58796890@phx.gbl>
James Im wrote:
> I just find out that I cannot continue using a connection when I use
> autocommit=false and that an sql insert failed.
That's intended behavior in PostgreSQL. I just wrote this in another
thread last week:
If you have a statement in your transaction that you know might fail,
you can use savepoints to avoid having to restart the whole transaction:
Savepoint sp = conn.setSavepoint();
try {
stmt.executeQuery("SELECT 1 FROM table_that_might_not_exist");
} catch(SQLException ex)
{
sp.rollback(sp);
}
stmt.executeQuery("SELECT * FROM table_that_exists");
...
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
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: heikki@enterprisedb.com, im-james@hotmail.com
Subject: Re: how to continue using a connection after an error with autocommit=false
In-Reply-To: <45DAD28A.2010907@enterprisedb.com>
References: <BAY7-F2720A1254B9177F763D58796890@phx.gbl> <45DAD28A.2010907@enterprisedb.com>
* 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