When we need to use connection.releaseSavepoint(sp); ?

"Any savepoints that have been created in a transaction are automatically released and become invalid when the transaction is committed, or when the entire transaction is rolled back."when we using transaction, we always end up with commit or rollback. so does releaseSavepoint
[299 byte] By [j_shadinataa] at [2007-11-27 6:15:04]
# 1

Savepoints consume resources, so you might conceivably want to release a savepoint that you had determined you would never need to roll back to. For example if you were running a loop to perform operations on the database you might well establish a savepoint at the beginning of the loop, but on each iteration want to release the previous savepoint.

In practice it tends not to be very useful. If you need to ask the question you probably don't need to use it.

dcmintera at 2007-7-12 17:25:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
> Savepoints consume resources, so you might conceivably want to release a savepoint that you had determined you would never need to roll back to.then we should call commit.
j_shadinataa at 2007-7-12 17:25:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
i understand now. perhaps when we have savepoints before a loop & inside that loop. we may release savepoint of previous loop but not certain to commit. we still may rollback to save point before loop.
j_shadinataa at 2007-7-12 17:25:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> i understand now.

No you don't, read my reply more carefully. I meant exactly what I said.

(edit) Here's an example to make it clearer:

Connection c = ...

try {

c.setAutoCommit(false); // Begin TX

for( int i = 0; i < 10000; i++ ) {

Savepoint s = c.setSavepoint("Loop savepoint " + i);

// perform update on database for index i

...

// perform read on database for index i

...

if( !isResultAsExpected() ) {

c.rollback(s);

} else {

// Prevents the savepoint from consuming

// resources in perpetuity.

c.releaseSavepoint(s);

}

}

// Only commit when all processing complete

c.commit();

} catch( SQLException e ) {

rollbackAndLog("...",c,e);

} finally {

close(c);

}

dcmintera at 2007-7-12 17:25:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
okay, thank you.what i mean was like your code doing except i don't realize we don't need to set a save point before the loop. when we call rollback without savepoint, we'll roll back to last commit or beginning transaction.
j_shadinataa at 2007-7-12 17:25:09 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...