Method for setting savepoint of transaction rollback in JDBC usage of Java

New JDBC 3 The interface to the 0 savepoint provides additional transaction control. Most modern DBMS in their environment, such as Oracle's PL / SQL, support savepoints.

When a savepoint is set, a logical rollback point is defined in the transaction. If an error occurs and a savepoint has been saved in the past, you can use the rollback method to undo either all changes or only changes made after the savepoint.

The connection object has two new methods to help manage savepoints:

Setsavepoint (string savepointname): defines a new savepoint. It also returns a savepoint object.

Release savepoint (savepoint savepointname): deletes a savepoint. Note that it requires a savepoint object as a parameter. This object is usually a savepoint generated by the setsavepoint () method.

There is a rollback (string savepointname) method to rollback work to the specified savepoint.

The following example demonstrates how to use the savepoint object:

In this case, without the above insert statement, it will succeed and everything will be rolled back. The following is an example of using setsavepoint and the transaction tutorial to describe rollback.

Based on the environment and database installation, this sample code has been explained in the previous chapters.

Copy the following example JDBC example Java, compile and run as follows:

Now let's compile the above example as follows:

When running JDBC example, it produces the following results:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>