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

Re: how to continue using a connection after an error with autocommit=false

From: Heikki Linnakangas <heikki(at)enterprisedb(dot)com>
To: James Im <im-james(at)hotmail(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: how to continue using a connection after an error with autocommit=false
Date: 2007-02-20 10:50:50
Message-ID: 45DAD28A.2010907@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
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

In response to

Responses

pgsql-jdbc by date

Next:From: Altaf MalikDate: 2007-02-20 10:53:46
Subject: Re: how to continue using a connection after an error with autocommit=false
Previous:From: James ImDate: 2007-02-20 10:48:43
Subject: invalid byte sequence for encoding "UTF8": 0x00

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