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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-interfaces by date

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