pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Cannot commit when autoCommit is enabled error
3+ messages / 3 participants
[nested] [flat]

* Cannot commit when autoCommit is enabled error
@ 2013-09-18 13:39  Gurkan Ozfidan <gurkan@resolution.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Gurkan Ozfidan @ 2013-09-18 13:39 UTC (permalink / raw)
  To: pgsql-jdbc

Dear group,
We have been using postgresql-jdbc-8.3-604, and recently we started using
postgresql-jdbc-9.2, everything seems working fine, except we are getting
this error and could not find the solution yet. This related to our
reporting and I could say that it is not happening every report we run. If
you could help, I really appreciated.
Below is the part of the code and error that we are getting. Thanks.

ERROR:
ERROR in createReportTable(): Cannot commit when autoCommit is enabled.
org.postgresql.util.PSQLException: Cannot commit when autoCommit is enabled.
        at
org.postgresql.jdbc2.AbstractJdbc2Connection.commit(AbstractJdbc2Connection.java:703)
        at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
        at
org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
        at
org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
        at $Proxy0.commit(Unknown Source)
        at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at
org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:40)
        at $Proxy125.commit(Unknown Source)
        at
com.resolution.scheduler.dao.hibernate.SalesPAFNewDaoHibernate.runStorageSQLQuery(SalesPAFNewDaoHibernate.java:219)
        at
com.resolution.scheduler.service.impl.SalesPAFNewManagerImpl.runStorageSQLQuery(SalesPAFNewManagerImpl.java:151)


PART OF THE CODE:

public Integer runStorageSQLQuery(String sqlQuery) throws Exception {
        int results=0;
        try {
            java.sql.Connection conn = getSession().connection();
            boolean acs = conn.getAutoCommit();
            //System.out.println("........
...........AutoCommit status: "+acs);
            conn.setAutoCommit(false);
            java.sql.PreparedStatement st = conn.prepareStatement(sqlQuery);
            results = st.executeUpdate();
            conn.commit();
            conn.setAutoCommit(acs);
            st.close();
        } catch (Exception e) {
            System.err.println("ERROR in runStorageSQLQuery(): " +
e.getMessage() + " sqlQuery: "+sqlQuery);
            e.printStackTrace();
        }
        return new Integer(results);
    }

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Cannot commit when autoCommit is enabled error
@ 2013-09-18 15:04  Dave Cramer <pg@fastcrypt.com>
  parent: Gurkan Ozfidan <gurkan@resolution.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Dave Cramer @ 2013-09-18 15:04 UTC (permalink / raw)
  To: Gurkan Ozfidan <gurkan@resolution.com>; +Cc: pgsql-jdbc

The code you showed looks fine. Are you sure this is where it is happening


Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca


On Wed, Sep 18, 2013 at 9:39 AM, Gurkan Ozfidan <gurkan@resolution.com>wrote:

> Dear group,
> We have been using postgresql-jdbc-8.3-604, and recently we started using
> postgresql-jdbc-9.2, everything seems working fine, except we are getting
> this error and could not find the solution yet. This related to our
> reporting and I could say that it is not happening every report we run. If
> you could help, I really appreciated.
> Below is the part of the code and error that we are getting. Thanks.
>
> ERROR:
> ERROR in createReportTable(): Cannot commit when autoCommit is enabled.
> org.postgresql.util.PSQLException: Cannot commit when autoCommit is
> enabled.
>         at
> org.postgresql.jdbc2.AbstractJdbc2Connection.commit(AbstractJdbc2Connection.java:703)
>         at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
>         at
> org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)
>         at
> org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)
>         at $Proxy0.commit(Unknown Source)
>         at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at
> org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:40)
>         at $Proxy125.commit(Unknown Source)
>         at
> com.resolution.scheduler.dao.hibernate.SalesPAFNewDaoHibernate.runStorageSQLQuery(SalesPAFNewDaoHibernate.java:219)
>         at
> com.resolution.scheduler.service.impl.SalesPAFNewManagerImpl.runStorageSQLQuery(SalesPAFNewManagerImpl.java:151)
>
>
> PART OF THE CODE:
>
> public Integer runStorageSQLQuery(String sqlQuery) throws Exception {
>         int results=0;
>         try {
>             java.sql.Connection conn = getSession().connection();
>             boolean acs = conn.getAutoCommit();
>             //System.out.println("........
> ...........AutoCommit status: "+acs);
>             conn.setAutoCommit(false);
>             java.sql.PreparedStatement st =
> conn.prepareStatement(sqlQuery);
>             results = st.executeUpdate();
>             conn.commit();
>             conn.setAutoCommit(acs);
>             st.close();
>         } catch (Exception e) {
>             System.err.println("ERROR in runStorageSQLQuery(): " +
> e.getMessage() + " sqlQuery: "+sqlQuery);
>             e.printStackTrace();
>         }
>         return new Integer(results);
>     }
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Cannot commit when autoCommit is enabled error
@ 2013-09-18 18:58  Kevin Grittner <kgrittn@ymail.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Kevin Grittner @ 2013-09-18 18:58 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; Gurkan Ozfidan <gurkan@resolution.com>; +Cc: pgsql-jdbc

Dave Cramer <pg@fastcrypt.com> wrote:
> Gurkan Ozfidan <gurkan@resolution.com> wrote:

>> ERROR in createReportTable(): Cannot commit when autoCommit is enabled.

>>         } catch (Exception e) {
>>             System.err.println("ERROR in runStorageSQLQuery(): " + e.getMessage() + " sqlQuery: "+sqlQuery);

> The code you showed looks fine. Are you sure this is where it is
> happening

I already pointed out on the -general list before they posted here
that the error message they are getting could not have come from
the code they show.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2013-09-18 18:58 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-18 13:39 Cannot commit when autoCommit is enabled error Gurkan Ozfidan <gurkan@resolution.com>
2013-09-18 15:04 ` Dave Cramer <pg@fastcrypt.com>
2013-09-18 18:58   ` Kevin Grittner <kgrittn@ymail.com>

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