Statement.setQueryTimeout() with autoCommit=false - Mailing list pgsql-jdbc

From pavel.arnost@loutka.cz
Subject Statement.setQueryTimeout() with autoCommit=false
Date
Msg-id 5097e057-c9b9-42f0-bed0-219eab05bb7d@googlegroups.com
Whole thread Raw
Responses Re: Statement.setQueryTimeout() with autoCommit=false  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-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


pgsql-jdbc by date:

Previous
From: Zsolt Kúti
Date:
Subject: Re: The column name was not found in this ResultSet
Next
From: Dave Cramer
Date:
Subject: Re: Statement.setQueryTimeout() with autoCommit=false