0

I'm using JDBC but I got some problems with rollback and savepoint. I can't understand why this code actually doesn't rollback to the savepoint and the record inserted remains.

try  {
    conn.setAutoCommit(false);
    stmt = conn.createStatement();

    sp = conn.setSavepoint();
    stmt.executeUpdate("INSERT INTO test(id) VALUES(" + args[0] + ")");

    if(true)  {
        conn.rollback(sp);
        System.out.println("rollback");
    }
} catch (SQLException ex)  {
    // handle any errors
    System.out.println("SQLException: " + ex.getMessage());
    System.out.println("SQLState: " + ex.getSQLState());
    System.out.println("VendorError: " + ex.getErrorCode());

    System.out.println("rollback");
    conn.rollback(sp);
} finally  {
    conn.commit();
}

Thanks in advance.

alkz
  • 337
  • 2
  • 7
  • 17

1 Answers1

0

Because Savepoint is just the DBMS's feature. I think it may be your database engine's problem.

You can check this question.

Community
  • 1
  • 1
bhuang3
  • 3,493
  • 2
  • 17
  • 17