JDBC (executing transactions coding style) - Mailing list pgsql-interfaces

From Constantin Teodorescu
Subject JDBC (executing transactions coding style)
Date
Msg-id 3715C329.9739047D@flex.ro
Whole thread Raw
Responses Re: [INTERFACES] JDBC (executing transactions coding style)
List 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

pgsql-interfaces by date:

Previous
From: Constantin Teodorescu
Date:
Subject: Re: [INTERFACES] pg_get_view unknow ...
Next
From: "admin"
Date:
Subject: JDBC and Postgres