pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Assad Jarrahian <jarraa@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: problems with currval and rollback
Date: Thu, 22 Dec 2005 18:37:49 -0700
Message-ID: <4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.com> (raw)

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



view thread (2+ messages)  latest in thread

Message-ID: <4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.com>
Permalink:  ../4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.com/
Also on:    postgresql.org/message-id/4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.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: jarraa@gmail.com
  Subject: Re: problems with currval and rollback
  In-Reply-To: <4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.com>
  References: <4bd3e1480512221737h2c43739epd1c9640e1d2cea0@mail.gmail.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