committing an aborted transaction

Поиск
Список
Период
Сортировка
От fschmidt
Тема committing an aborted transaction
Дата
Msg-id 20519423.post@talk.nabble.com
обсуждение исходный текст
Ответы Re: committing an aborted transaction  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-jdbc
If one commits an aborted transaction, it seems to rollback without any
notice.  Whether a transaction should be aborted by an exception seems
debatable, but to have a commit quietly rollback instead is terrible design.
Committing an aborted transaction should throw an exception.  Below is an
example program:


import java.sql.*;

public class P {
    public static void main(String[] args) throws Exception {
        Class.forName("org.postgresql.Driver");
        Connection con =
DriverManager.getConnection("jdbc:postgresql://localhost/n1","postgres","word");
        Statement stmt = con.createStatement();
        stmt.executeUpdate("drop table if exists t");
        stmt.executeUpdate("create table t (id integer)");
        stmt.close();

        con.setAutoCommit(false);
        stmt = con.createStatement();
        stmt.executeUpdate("insert into t (id) values (1)");
        ResultSet rs = stmt.executeQuery("select * from t where id=1");
        System.out.println( (rs.next() ? "ok" : "not found") + " in transaction");
        try {
            stmt.executeUpdate("nonsense");
        } catch(SQLException e) {}
        stmt.close();
        con.commit();

        con.setAutoCommit(true);
        stmt = con.createStatement();
        rs = stmt.executeQuery("select * from t where id=1");
        System.out.println( (rs.next() ? "ok" : "not found") + " after
transaction");
        stmt.executeUpdate("drop table if exists t");
        stmt.close();
        con.close();
    }
}

--
View this message in context: http://www.nabble.com/committing-an-aborted-transaction-tp20519423p20519423.html
Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.


В списке pgsql-jdbc по дате отправления:

Предыдущее
От: "Jay Howard"
Дата:
Сообщение: Re: passing user defined data types to stored procedures
Следующее
От: Tom Lane
Дата:
Сообщение: Re: committing an aborted transaction