Skip site navigation (1) Skip section navigation (2)

problems with currval and rollback

From: Assad Jarrahian <jarraa(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: problems with currval and rollback
Date: 2005-12-23 01:37:49
Message-ID: 4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
Hi all,
  So I started to make some changes with my jdbc code here and there
(nothing to do with the relevant lines) and suddenly currval and
rollback don't work.

             try{
                       db.setAutoCommit(false);
                       addLM.setInt(1, lm.getOrigin());
                          .......
                    addLM.executeUpdate();
                    sql = db.createStatement();
                     ResultSet result = sql.executeQuery("SELECT
currval('lm_id_seq');");
                       if (result. next()){
                               db.commit();
                               db.setAutoCommit(true);
                        else{
                               db.rollback(); //reverse all changes
                               db.setAutoCommit(true);
                      }
               catch(SQLException ex){
                       try {
                               db.rollback();
                               db.setAutoCommit(true);
                       } catch (SQLException e) {
                               throw e;
                      }
                       throw ex;
          }

What happens is that the it inserts a db, but cannot get a value back
using currval  (ERROR: ERROR: currval of sequence "lm_id_seq" is not
yet defined in this session 55000  ) , yet the db gets the addlm
inserted. It should rollback, but it does not. What gives?

I ran the insert-currval combo  from psql and it worked.
What gives?


Any help would be appreciated.

-assad

Responses

pgsql-jdbc by date

Next:From: Oliver JowettDate: 2005-12-23 03:12:39
Subject: Re: problems with currval and rollback
Previous:From: Mike CharnokyDate: 2005-12-22 21:35:09
Subject: Re: Driver compatibility with 7.3 server

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group