Re: Statement.setQueryTimeout() with autoCommit=false

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: pavel(dot)arnost(at)loutka(dot)cz
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Statement.setQueryTimeout() with autoCommit=false
Date: 2012-12-06 17:54:48
Message-ID: CADK3HHL4G0HCj-v2L-tp2EhqNP=tuuZZqzSTMSCahWbFZdsH5A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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, <pavel(dot)arnost(at)loutka(dot)cz> wrote:

> Hi,
>
> does setQueryTimeout work with autoCommit=false? When autoCommit is true,
> this code timeouts after 5 seconds (as expected):
>
> --
> Class.forName("org.postgresql.Driver");
> String url = "jdbc:postgresql://172.30.100.6/test";
> Properties props = new Properties();
> props.setProperty("user", "postgres");
> props.setProperty("password", "");
>
> Connection conn = DriverManager.getConnection(url, props);
> PreparedStatement st = conn.prepareStatement("INSERT INTO test
> VALUES('xxx')");
> st.setQueryTimeout(5);
> st.execute();
> --
>
> But if I set autoCommit to false, this code timeouts after 30 seconds on
> read timeout:
>
> --
> Class.forName("org.postgresql.Driver");
> String url = "jdbc:postgresql://172.30.100.6/test";
> Properties props = new Properties();
> props.setProperty("user", "postgres");
> props.setProperty("password", "");
>
> Connection conn = DriverManager.getConnection(url, props);
> conn.setAutoCommit(false);
> PreparedStatement st = conn.prepareStatement("INSERT INTO test
> VALUES('xxx')");
> st.setQueryTimeout(5);
> st.execute();
> conn.commit();
> --
>
> I'm confused what's setQueryTimeout() method for, why it doesn't work with
> manual transactions?
>
> Thanks,
> Regards
> Pavel
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message dmp 2012-12-06 18:14:50 Re: Statement.setQueryTimeout() with autoCommit=false
Previous Message pavel.arnost 2012-12-06 17:04:41 Statement.setQueryTimeout() with autoCommit=false