View Single Post

   
  #2 (permalink)  
Old 04-16-2008, 12:36 AM
Heikki Linnakangas
 
Posts: n/a
Default Re: how to continue using a connection after an error withautocommit=false

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

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Reply With Quote