pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pavel.arnost@loutka.cz
To: pgsql-jdbc@postgresql.org
Subject: Statement.setQueryTimeout() with autoCommit=false
Date: Thu, 6 Dec 2012 09:04:41 -0800 (PST)
Message-ID: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



view thread (14+ messages)  latest in thread

Message-ID: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com>
Permalink:  ../5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com/
Also on:    postgresql.org/message-id/5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.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: pavel.arnost@loutka.cz
  Subject: Re: Statement.setQueryTimeout() with autoCommit=false
  In-Reply-To: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com>
  References: <5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.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