Обсуждение: transaction abortion

Поиск
Список
Период
Сортировка

transaction abortion

От
Michele Laghi
Дата:
Hi,
I am faced to the following problem:
...
conn.setAutoCommit(false);
String[] val = new String[] {"one", "two", "two", "three" };
for (int i=0; i < nmax; i++) {
    try {
       PreparedStatement
          pst = conn.prepareStatement("INSERT INTO ATEST VALUES (?)");
       pst.setString(1, val[i]);
       int ret = pst.executeUpdate();
    }
    catch (SQLException ex) { /* handle exception here */ }
}
conn.commit();
...

The inserted element is a primary key. What I want is to ignore the
insertion of entries which are already in the DB. This works fine with
Oracle and hsqldb but with Postgres the SQLException implicitly aborts
the transaction. Is this behaviour correct or is it a bug ?
If it is correct, is there a way to inhibit the abortion of the
transaction ? I am using v. 7.3.2 and as a driver jdbc7.2dev-1.2.jar

Regards
Michele