Re: JDBC gripe list (the autocommit subthread) - Mailing list pgsql-jdbc

From Kevin Grittner
Subject Re: JDBC gripe list (the autocommit subthread)
Date
Msg-id 4D94C299020000250003C0A7@gw.wicourts.gov
Whole thread Raw
In response to Re: JDBC gripe list (the autocommit subthread)  (Oliver Jowett <oliver@opencloud.com>)
Responses Re: JDBC gripe list (the autocommit subthread)  (Oliver Jowett <oliver@opencloud.com>)
Re: JDBC gripe list (the autocommit subthread)  ("A.M." <agentm@themactionfaction.com>)
List pgsql-jdbc
Oliver Jowett <oliver@opencloud.com> wrote:

> (b) the current behavior is consistent with how multiple statement
> execution works elsewhere in the driver, where if you execute
> "SELECT a; SELECT b" as a statement with autocommit=true then the
> two queries run in a single transaction;

I did not know that.  Is that required by spec?

It definitely doesn't happen in psql:

test=# select now(); select now();
              now
-------------------------------
 2011-03-31 17:38:41.345244-05
(1 row)

              now
-------------------------------
 2011-03-31 17:38:41.410403-05
(1 row)

test=# begin; select now(); select now(); commit;
BEGIN
              now
-------------------------------
 2011-03-31 17:38:58.593238-05
(1 row)

              now
-------------------------------
 2011-03-31 17:38:58.593238-05
(1 row)

COMMIT

I would have expected more or less the same from this:

import java.sql.*;
public class MultiStmt
{
    public static void main(String[] args) throws Exception
    {
        Class.forName("org.postgresql.Driver");
        Connection con = DriverManager.getConnection
            ("jdbc:postgresql:test", "kgrittn", "");
        Statement stmt = con.createStatement();
        for (boolean rsfound = stmt.execute
                ("select now(); select now();");
             rsfound || stmt.getUpdateCount() != -1;
             rsfound = stmt.getMoreResults())
        {
            ResultSet rs = stmt.getResultSet();
            while (rs.next())
                System.out.println
                    (rs.getTimestamp(1));
            rs.close();
        }
        stmt.close();
        con.close();
    }
}

When I run that, I see that it behaves as you say.

-Kevin

pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: JDBC gripe list (the autocommit subthread)
Next
From: Oliver Jowett
Date:
Subject: Re: JDBC gripe list (the autocommit subthread)