Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgiNF-00022f-3I for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 20:48:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TgiND-00020R-Un for pgsql-jdbc@arkaria.postgresql.org; Thu, 06 Dec 2012 20:48:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgiFx-0001V8-D7 for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 20:41:17 +0000 Received: from news.hub.org ([200.46.204.72]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TgiFs-0008QJ-Ix for pgsql-jdbc@postgresql.org; Thu, 06 Dec 2012 20:41:17 +0000 Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.5/8.14.5) with ESMTP id qB6KfBoO059344 for ; Thu, 6 Dec 2012 16:41:11 -0400 (AST) (envelope-from news@news.hub.org) Received: from news.hub.org (news@localhost) by news.hub.org (8.14.5/8.14.5/Submit) with NNTP id qB6KXMU0058657 for pgsql-jdbc@postgresql.org; Thu, 6 Dec 2012 16:33:22 -0400 (AST) (envelope-from news) Received: by 10.66.75.230 with SMTP id f6mr607231paw.25.1354826002100; Thu, 06 Dec 2012 12:33:22 -0800 (PST) Received: by 10.50.91.230 with SMTP id ch6mr1049054igb.9.1354826002051; Thu, 06 Dec 2012 12:33:22 -0800 (PST) X-Newsgroups: pgsql.interfaces.jdbc Date: Thu, 6 Dec 2012 12:33:21 -0800 (PST) In-Reply-To: <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=84.42.209.109; posting-account=Y2aaMAoAAABH9DJbJzVnp21hz7eFNnF7 References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> <50C0E09A.4070408@ttc-cmc.net> <014101cdd3e0$a9a302a0$fce907e0$@yahoo.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <5a57e55f-1b8f-4f37-a271-af9fb1a9ffab@googlegroups.com> Subject: Re: Statement.setQueryTimeout() with autoCommit=false From: =?UTF-8?Q?Pavel_Arno=C5=A1t?= Injection-Date: Thu, 06 Dec 2012 20:33:22 +0000 Content-Type: text/plain; charset=ISO-8859-1 To: pgsql-jdbc@postgresql.org X-Pg-Spam-Score: -1.9 (-) 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 If that's how it works, why this code timeouts after 5 seconds?: -- Connection conn = DriverManager.getConnection(url, props); conn.setAutoCommit(false); final PreparedStatement st = conn.prepareStatement("INSERT INTO test VALUES('xxx')"); st.setQueryTimeout(5); st.execute(); Timer timer = new Timer(true); TimerTask cancelTimer = new TimerTask() { public void run() { try { st.cancel(); } catch (SQLException e) { } } }; timer.schedule(cancelTimer, 5000); conn.commit(); -- Quick look at AbstractJdbc2Statement.execute() shows me that setQueryTimeout() works with Timer/TimerTask like this one. Thanks, Pavel 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=false > > > > > > 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=false? 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 -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc