Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgibY-0002Gr-Fm for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 21:03:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TgibY-0003Xi-0L for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 21:03:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgibX-0003Xd-4b for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 21:03:35 +0000 Received: from nm10.bullet.mail.bf1.yahoo.com ([98.139.212.169]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgibT-0000N8-PG for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 21:03:34 +0000 Received: from [98.139.212.145] by nm10.bullet.mail.bf1.yahoo.com with NNFMP; 06 Dec 2012 21:03:29 -0000 Received: from [76.13.13.46] by tm2.bullet.mail.bf1.yahoo.com with NNFMP; 06 Dec 2012 21:03:29 -0000 Received: from [127.0.0.1] by smtp107.prem.mail.ac4.yahoo.com with NNFMP; 06 Dec 2012 21:03:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1354827809; bh=7KMXE73hcxLNGdtTg3tUNjb2CHvGk+uRSvH+2ALyHvM=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=IEP1qPe5109QhfEqw/PkhmQGt8NKYrUoEWAL8oEork1jyKK7ONSNltrLEDrWi3h8Zb6DPHbzZVTpg9q/zh2CQOVotoCjt/Yf8w6MXkjlE93tEUNaLlu9ljaC8vrktHPwUhDm6N5gNQi5XmmWl6P4O79zeLp8tLJaXbVtnGiCP0I= X-Yahoo-Newman-Id: 751429.82784.bm@smtp107.prem.mail.ac4.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: aga.LkUVM1nI5LmFl7QQHVbI5UhF6sX.VgVYWyUGTZd19fr _3gmV_yS0d6_fwo5xply.wnOUDDXz.7WX3_0OegdO56kDMUO_B_x7fCu5._O Cy8amRJ4BhkbvixDNgWOfwg4MpIGW9PWr7eBh406vdyv1o6ROWbEaiQrchG5 0LKPXdwKroOKbIGU_GwF1IPUXnf_rbzDl4bxYTnkGmUTY4J_eciEFzSsbeu8 z.RXuZFBHM13sGwe9CY65gq3Ef8i.UxrmUnBuLSxVEQoM8LKFkoS9fE7acg2 YcjMogKH35Ff4DKoASsKdRNl52ej_Ii1d3B63nuPp_ikJEawDTlmtT9WoEhy g1LktciMUI3ckVEQmN6JE_j0xliQDSB4h9dEtOLTMbA7fu5teH.H.SoOvpgq LNOeJjQ6PgpqgTVyGxMj9lsUQgGoZ2yuU.8v80Dy1g4dAv5nGCfd0qChiPeU ZlEbgPGS0gTikA5xHGUVJ2cHRIl7UEgo816AfMlURZFCLPNXKOqUYEKmimVh lSpg- X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.28.86 with login) by smtp107.prem.mail.ac4.yahoo.com with SMTP; 06 Dec 2012 13:03:29 -0800 PST From: "David Johnston" To: =?iso-8859-2?Q?'Pavel_Arno=B9t'?= , References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> In-Reply-To: <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> Subject: Re: Statement.setQueryTimeout() with autoCommit=false Date: Thu, 6 Dec 2012 16:03:17 -0500 Message-ID: <016e01cdd3f5$1dbdaaf0$593900d0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQF71Xk46Ti56BxJT15wxGI4l97bCgL5hfPWAUAjiNcC3ghMCQGv1N9rmGoBDBA= Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org It may be that I am wrong and at the moment haven't tested your examples but it seems odd that you can st.cancel() after st.execute() without getting some kind of exception (which you are ignoring in your catch block). Without some more detail I either need to do some testing on my own or leave it to more qualified individuals to help. I'll admit I am making untested assumptions here about how the interaction should behave (but often my idea of "should behave" differs from reality). David J. > -----Original Message----- > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > owner@postgresql.org] On Behalf Of Pavel Arno=B9t > Sent: Thursday, December 06, 2012 3:33 PM > To: pgsql-jdbc@postgresql.org > Subject: Re: [JDBC] Statement.setQueryTimeout() with autoCommit=3Dfalse >=20 > If that's how it works, why this code timeouts after 5 seconds?: >=20 > -- > Connection conn =3D DriverManager.getConnection(url, props); > conn.setAutoCommit(false); > final PreparedStatement st =3D conn.prepareStatement("INSERT INTO test > VALUES('xxx')"); > st.setQueryTimeout(5); > st.execute(); >=20 > Timer timer =3D new Timer(true); >=20 > TimerTask cancelTimer =3D new TimerTask() { > public void run() { > try { > st.cancel(); > } catch (SQLException e) { } > } > }; >=20 > timer.schedule(cancelTimer, 5000); >=20 > conn.commit(); > -- >=20 > Quick look at AbstractJdbc2Statement.execute() shows me that > setQueryTimeout() works with Timer/TimerTask like this one. >=20 > Thanks, > Pavel >=20 > On Thursday, December 6, 2012 7:36:53 PM UTC+1, "David Johnston" wrote: > > > -----Original Message----- > > > > > From: pgsql-jdbc-owner@postgresql.org [mailto:pgsql-jdbc- > > > > > owner@postgresql.org] On Behalf Of dmp > > > > > Sent: Thursday, December 06, 2012 1:15 PM > > > > > To: pgsql-jdbc@postgresql.org > > > > > Cc: pavel.arnost@loutka.cz > > > > > Subject: Re: [JDBC] Statement.setQueryTimeout() with > > > autoCommit=3Dfalse > > > > > > > > > > Exactly. > > > > > > > > > > According to the Java API: > > > > > > > > > > void setAutoCommit(boolean autoCommit) throws SQLException > > > > > > > > > > Sets this connection's auto-commit mode to the given state. If > > > a > > > > > connection is in auto-commit mode, then all its SQL statements will > > > be > > > > > executed and committed as individual transactions. Otherwise, its > > > SQL > > > > > statements are grouped into transactions that are terminated by a > > > call to > > > > > either the method commit or the method rollback. By default, new > > > > > connections are in auto-commit mode. > > > > > > > > > > By setting setAutoCommit(false) you are deciding to tell the > > > database your > > > > > code will determine when to commit the transaction. Thereby I would > > > say > > > > > overiding setQueryTimeout(). > > > > > > > > > > danap. > > > > > > > > Even within an manually administered transaction the setting of > > > > "setQueryTimeout()" will (should?) act on the individual statements > > that > > > > make up the transaction. If any individual statement within the > > transaction > > > > exceeds the limit that statement will fail and thus put the > > transaction into > > > > a "failed" state where a rollback (possibly to savepoint) is required. > > The > > > > transaction itself does not constitute a statement and as such it can > > run > > > > indefinitely long regardless of the presence of a statement timeout. > > > > > > > > David J. > > > > > > > > > > > > > > Dave Cramer wrote: > > > > > > Why would the query timeout at all ? > > > > > > > > > > > > The query timeout is for long running queries. If the query takes > > > > > > longer than n seconds it will timeout. > > > > > > > > > > > > Dave > > > > > > > > > > > > Dave Cramer > > > > > > > > > > > > dave.cramer(at)credativ(dot)ca > > > > > > http://www.credativ.ca > > > > > > > > > > > > > > > > > > > > > > > > On Thu, Dec 6, 2012 at 12:04 PM, > > > > > > wrote: > > > > > > > > > > > > Hi, > > > > > > > > > > > > does setQueryTimeout work with autoCommit=3Dfalse? When > > > > autoCommit > > > > > is > > > > > > true, this code timeouts after 5 seconds (as expected): > > > > > > > > > > > > ~ > > > > > > ~ > > > > > > ~ > > > > > > -- > > > > > > > > > > > > But if I set autoCommit to false, this code timeouts after 30 > > > > > > seconds on read timeout: > > > > > > > > > > > > -- > > > > > > ~ > > > > > > ~ > > > > > > ~ > > > > > > -- > > > > > > > > > > > > I'm confused what's setQueryTimeout() method for, why it > > > > doesn't > > > > > > work with manual transactions? > > > > > > > > > > > > > > > -- > > > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make > > > > changes > > > > > to your subscription: > > > > > http://www.postgresql.org/mailpref/pgsql-jdbc > > > > > > > > > > > > > > > > -- > > > > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > > > > To make changes to your subscription: > > > > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 >=20 >=20 > -- > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes > to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc