pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Eric Faulhaber <ecf@goldencode.com>
To: pgsql-jdbc@postgresql.org
Subject: Implicit autocommit?
Date: Sun, 15 Jul 2007 02:10:25 -0400
Message-ID: <4699BA51.6050001@goldencode.com> (raw)

I am using postgresql-8.1-408.jdbc3.jar w/ PostgreSQL 8.1.8 on Kubuntu 
Linux.

Given the following testcase (note autocommit is disabled)...

--------- BEGIN SOURCE -----------
import java.sql.*;

public class VacuumTest
{
   public static void main(String[] args)
   throws SQLException
   {
      Connection conn = null;
      try
      {
         Class.forName("org.postgresql.Driver");
         conn = 
DriverManager.getConnection("jdbc:postgresql://localhost/test");
         conn.setAutoCommit(false);

         update(conn, "create temp table tt1 (c1 int4)");
         update(conn, "vacuum tt1");
         update(conn, "drop table tt1");
      }
      catch (Exception exc)
      {
         exc.printStackTrace();
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }

   private static void update(Connection conn, String sql)
   throws SQLException
   {
      Statement stmt = conn.createStatement();
      try
      {
         stmt.executeUpdate(sql);
      }
      finally
      {
         stmt.close();
      }
   }
}
---------- END SOURCE ------------

...I see the following result:

org.postgresql.util.PSQLException: ERROR: VACUUM cannot run inside a 
transaction block
        at 
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1531)
        at 
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1313)
        at 
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:188)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:452)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:340)
        at 
org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:286)
        at VacuumTest.update(VacuumTest.java:38)
        at VacuumTest.main(VacuumTest.java:16)

I debugged into the driver and found it was issuing a "BEGIN" to the 
backend just before each statement.  Why would it do this with 
autocommit disabled?

Thanks,
Eric Faulhaber




view thread (5+ messages)  latest in thread

Message-ID: <4699BA51.6050001@goldencode.com>
Permalink:  ../4699BA51.6050001@goldencode.com/
Also on:    postgresql.org/message-id/4699BA51.6050001@goldencode.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: ecf@goldencode.com
  Subject: Re: Implicit autocommit?
  In-Reply-To: <4699BA51.6050001@goldencode.com>
  References: <4699BA51.6050001@goldencode.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