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

JDBC (executing transactions coding style)

From: Constantin Teodorescu <teo(at)flex(dot)ro>
To: PostgreSQL Interfaces <pgsql-interfaces(at)postgresql(dot)org>
Subject: JDBC (executing transactions coding style)
Date: 1999-04-15 10:44:57
Message-ID: 3715C329.9739047D@flex.ro (view raw or flat)
Thread:
Lists: pgsql-interfaces
I want to execute multiple SQL commands (also insert,updates and selects
) in a transaction block.

Is the following coding style correct ?

Statement st;
ResultSet rs;

try {
  st.executeUpdate("BEGIN");
  st.executeUpdate("INSERT INTO ...");
  st.executeUpdate("DELETE FROM ...");
  rs = st.executeQuery("SELECT FROM ...");
  if (rs != null) {
     while ( rs.next() ) {
       // do different things
     }
  }
  rs.close();
  st.executeUpdate("UPDATE ...");
  st.executeUpdate("COMMIT TRANSACTION");
} catch (SQLException sqle) {
  sqle.printStackTrace();
  // ABORT TRANSACTION NEEDED ?
}

What I want to know : is there necessary to do a st.executeUpdate("ABORT
TRANSACTION") in the catch instruction block ?
I recall that someone says that an error inside a transaction block
automatically aborts the transaction.
Is it true ? It works here ?

For other databases it might be necessary to do that.
Then, the st.executeUpdate("ABORT"); must be included also in another
try..catch block, true ?

Thanks a lot,
-- 
Constantin Teodorescu
FLEX Consulting Braila, ROMANIA

Responses

pgsql-interfaces by date

Next:From: adminDate: 1999-04-15 12:29:21
Subject: JDBC and Postgres
Previous:From: Constantin TeodorescuDate: 1999-04-15 08:26:44
Subject: Re: [INTERFACES] pg_get_view unknow ...

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