How can I roll back errors of multiple database updates in the same transaction through a program?

Source: Internet
Author: User
Tags savepoint connection reset

Specifically: Begin transaction // use a program to control the transaction.
// Connect database
Update the first row
// Update successfully
Update the second row
// Fail to update due to Connection lost.

How can I implement the first updated data in roll back. Test code: C. setautocommit (false );

Preparedstatement S = C. preparestatement ("insert into a values (?) ");

Savepoint S1 = C. setsavepoint ();

S. setstring (1, "333 ");
S.exe cuteupdate ();

Savepoint S2 = C. setsavepoint ();

S. setstring (1, "444 ");
S.exe cuteupdate ();

Savepoint S3 = C. setsavepoint ();

S. setstring (1, "555 ");
S.exe cuteupdate ();

C. rollback (S3 );
C. Commit ();

After debugging to update 444, manually disconnect the database and execute update 555, a familiar error will be reported: Java. SQL. sqlexception: Io exception: Connection reset by peer: Socket write error connects the database and queries Table A. The data in table A is empty, which indicates that both table 333 and table 444 are not saved. As long as setautocommit (false) is used, it will not be saved. The savepoint of Oracle is default and does not require any operations. However, if the when exception is used in SQL, the situation changes completely. Reference http://dev2dev.bea.com.cn/bbs/thread.jspa? Forumid = 123 & threadid = 42438 & messageid = 248011 #248011

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.