Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 88E949FBF09 for ; Wed, 11 Jul 2007 18:08:58 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 37187-01-3 for ; Wed, 11 Jul 2007 18:08:40 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.175]) by postgresql.org (Postfix) with ESMTP id 8518A9FBA12 for ; Wed, 11 Jul 2007 18:08:51 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id a2so220798ugf for ; Wed, 11 Jul 2007 14:08:48 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=LHtvwXdAoAVG/m0peAZhbP/p3lpGO7fhtPqfakdJiOiSO/hk/l9UnHpxf6ujL/pwA5DCKCF/m2KAJxKajVaxafXNm1PxJ9WNvWSNj3k1118tgJHHq8muU3O3b59x1yBCa4pDT2V3Nop9VVhWw9mkolIfE9xuDBJ8Ewzj6praNog= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=hfwaeWaZjA7sQfP6Ogn1lcAHouiAMWkkOuzSD86O9LRSXftQTMCEgLeUZZiOsKl8z2f6Dbis9t6TBMfQuDcaaYk0L+Y0z4689Gmz3P0NKfdvDcC92SgOlIkoKPnArcYoAtvHsxxqEir7elZMuO6UHesPuiOePQNiiLiwKeiGeLg= Received: by 10.66.242.20 with SMTP id p20mr696522ugh.1184188127998; Wed, 11 Jul 2007 14:08:47 -0700 (PDT) Received: from ?192.168.1.33? ( [86.27.136.187]) by mx.google.com with ESMTPS id n55sm483549uga.2007.07.11.14.08.45 (version=SSLv3 cipher=RC4-MD5); Wed, 11 Jul 2007 14:08:46 -0700 (PDT) Message-ID: <469546AB.5060905@enterprisedb.com> Date: Wed, 11 Jul 2007 22:07:55 +0100 From: Heikki Linnakangas User-Agent: Icedove 1.5.0.10 (X11/20070329) MIME-Version: 1.0 To: Fabian Zeindl CC: pgsql-jdbc@postgresql.org Subject: Re: questions regarding transactions References: <46953E79.5010204@xover.htu.tuwien.ac.at> In-Reply-To: <46953E79.5010204@xover.htu.tuwien.ac.at> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/43 X-Sequence-Number: 17217 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