pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki@enterprisedb.com>
To: Fabian Zeindl <fabian@xover.htu.tuwien.ac.at>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: questions regarding transactions
Date: Wed, 11 Jul 2007 22:07:55 +0100
Message-ID: <469546AB.5060905@enterprisedb.com> (raw)
In-Reply-To: <46953E79.5010204@xover.htu.tuwien.ac.at>
References: <46953E79.5010204@xover.htu.tuwien.ac.at>

Fabian Zeindl wrote:
> 1) Am I supposed to do "myConn.rollback()" on error? What happens if I
> don't do it - will the transaction stay half-committed?! (I ask this,
> because rollback() can throw a SQLException, so it's not guaranteed to
> work, in my opinion).

Yes. The transaction will stay open until you end it with commit, 
rollback, or disconnect the connection.

> 2) When I use statements like (SELECT currval('somesequence')) in a
> jdbc-transaction, will it be atomic to? Will the sequence be decremented
> again when the transaction fails? Can I get wrong numbers, when there is
> another transaction which increments somesequence?

Sequences are not transactional in that sense. If a transaction is 
rolled back, the sequence won't be decremented. If you really need to 
guarantee that there's no gaps in a series of numbers, you'll need to 
use other means.

I'm not sure what you mean by wrong numbers, but two transactions will 
never get the same number if that's what you mean. Sequences are safe to 
use concurrently from multiple transactions, that's what they're for.

> 3) Is it sufficient to do setAutocommit(false) and set the
> transaction-level or do I have to call a statement like "START
> TRANSACTION" to properly start an transaction? (I found
> the latter example somewhere on the net.)

setAutocommit is the right way to do it. You shouldn't issue BEGIN or 
any other transaction-related statements yourself.

-- 
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com



view thread (4+ messages)  latest in thread

Message-ID: <469546AB.5060905@enterprisedb.com>
Permalink:  ../469546AB.5060905@enterprisedb.com/
Also on:    postgresql.org/message-id/469546AB.5060905@enterprisedb.com

 · 

reply

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, fabian@xover.htu.tuwien.ac.at
  Subject: Re: questions regarding transactions
  In-Reply-To: <469546AB.5060905@enterprisedb.com>
  References: <46953E79.5010204@xover.htu.tuwien.ac.at> <469546AB.5060905@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