88 lines
6.6 KiB
HTML
88 lines
6.6 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html
|
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html lang="en-us" xml:lang="en-us">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="security" content="public" />
|
|
<meta name="Robots" content="index,follow" />
|
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
|
<meta name="DC.Type" content="concept" />
|
|
<meta name="DC.Title" content="Savepoints" />
|
|
<meta name="abstract" content="Savepoints allow the setting of "staging points" in a transaction. Savepoints are checkpoints that the application can roll back to without throwing away the entire transaction. Savepoints are new in JDBC 3.0, meaning that the application must run on Java Development Kit (JDK) 1.4 or a subsequent release to use them. Moreover, savepoints are new to the Developer Kit for Java, meaning that savepoints are not supported if JDK 1.4 or a subsequent release is not used with previous releases of the Developer Kit for Java." />
|
|
<meta name="description" content="Savepoints allow the setting of "staging points" in a transaction. Savepoints are checkpoints that the application can roll back to without throwing away the entire transaction. Savepoints are new in JDBC 3.0, meaning that the application must run on Java Development Kit (JDK) 1.4 or a subsequent release to use them. Moreover, savepoints are new to the Developer Kit for Java, meaning that savepoints are not supported if JDK 1.4 or a subsequent release is not used with previous releases of the Developer Kit for Java." />
|
|
<meta name="DC.Relation" scheme="URI" content="transactions.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="transaut.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="transiso.htm" />
|
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
|
<meta name="DC.Format" content="XHTML" />
|
|
<meta name="DC.Identifier" content="savepnts" />
|
|
<meta name="DC.Language" content="en-us" />
|
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
|
<!-- US Government Users Restricted Rights -->
|
|
<!-- Use, duplication or disclosure restricted by -->
|
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
|
<title>Savepoints</title>
|
|
</head>
|
|
<body id="savepnts"><a name="savepnts"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Savepoints</h1>
|
|
<div><p>Savepoints allow the setting of "staging points" in a transaction.
|
|
Savepoints are checkpoints that the application can roll back to without throwing
|
|
away the entire transaction. Savepoints are new in JDBC 3.0, meaning that
|
|
the application must run on Java™ Development Kit (JDK) 1.4 or a subsequent
|
|
release to use them. Moreover, savepoints are new to the Developer Kit for Java,
|
|
meaning that savepoints are not supported if JDK 1.4 or a subsequent release
|
|
is not used with previous releases of the Developer Kit for Java.</p>
|
|
<div class="note"><span class="notetitle">Note:</span> The system provides SQL statements for working with savepoints. It is
|
|
advised that JDBC applications do not use these statements directly in an
|
|
application. Doing so may work, but the JDBC driver loses its ability to track
|
|
the your savepoints when this is done. At a minimum, mixing the two models
|
|
(that is, using your own savepoint SQL statements and using the JDBC API)
|
|
should be avoided.</div>
|
|
<div class="section"><h4 class="sectiontitle">Set and roll back to savepoints</h4><p>Savepoints can be
|
|
set throughout the work of a transaction. The application can then roll back
|
|
to any of these savepoints if something goes wrong and continue processing
|
|
from that point. In the following example, the application inserts the value
|
|
FIRST into a database table. After that, a savepoint is set and another value,
|
|
SECOND, is inserted into the database. A rollback to the savepoint is issued
|
|
and undoes the work of inserting SECOND, but leaves FIRST as part of the pending
|
|
transaction. Finally, the value THIRD is inserted and the transaction is committed.
|
|
The database table contains the values FIRST and THIRD.</p>
|
|
<p><strong>Example:</strong> Set
|
|
and roll back to savepoints</p>
|
|
<div class="note"><span class="notetitle">Note:</span> Read the <a href="codedisclaimer.htm">Code
|
|
example disclaimer</a> for important legal information.</div>
|
|
<pre>Statement s = Connection.createStatement();
|
|
s.executeUpdate("insert into table1 values ('FIRST')");
|
|
Savepoint pt1 = connection.setSavepoint("FIRST SAVEPOINT");
|
|
s.executeUpdate("insert into table1 values ('SECOND')";);
|
|
connection.rollback(pt1); // Undoes most recent insert.
|
|
s.executeUpdate("insert into table1 values ('THIRD')");
|
|
connection.commit();</pre>
|
|
<p>Although it is unlikely to cause problems
|
|
to set savepoints while in auto-commit mode, they cannot be rolled back as
|
|
their lives end at the end of a transaction.</p>
|
|
</div>
|
|
<div class="section"><h4 class="sectiontitle">Release a savepoint</h4><p>Savepoints can be released by
|
|
the application with the releaseSavepoint method on the Connection object.
|
|
Once a savepoint has been released, attempting to roll back to it results
|
|
in an exception. When a transaction commits or rolls back, all savepoints
|
|
automatically release. When a savepoint is rolled back, other savepoints that
|
|
follow it are also released.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="transactions.htm" title="A transaction is a logical unit of work. To complete a logical unit of work, several actions may have to be taken against a database.">Transactions</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="transaut.htm" title="By default, JDBC uses an operation mode called auto-commit. This means that every update to the database is immediately made permanent.">Auto-commit mode</a></div>
|
|
<div><a href="transiso.htm" title="Transaction isolation levels specify what data is visible to statements within a transaction. These levels directly impact the level of concurrent access by defining what interaction is possible between transactions against the same target data source.">Transaction isolation levels</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |