JDBC (executing transactions coding style)

Поиск
Список
Период
Сортировка
От Constantin Teodorescu
Тема JDBC (executing transactions coding style)
Дата
Msg-id 3715C329.9739047D@flex.ro
обсуждение исходный текст
Ответы Re: [INTERFACES] JDBC (executing transactions coding style)
Список 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 по дате отправления:

Предыдущее
От: Constantin Teodorescu
Дата:
Сообщение: Re: [INTERFACES] pg_get_view unknow ...
Следующее
От: "admin"
Дата:
Сообщение: JDBC and Postgres