Manipulating SQLite databases with transactions

Source: Internet
Author: User
Tags sqlite
Use the Sqlitedatabase BeginTransaction () method to open a transaction where the program executes to the Endtransaction () method to check whether the flag of the transaction is successful if the program executes to Endtransaction () The Settransactionsuccessful () method was previously called to set the transaction's flag to commit the transaction successfully, and if the Settransactionsuccessful () method was not called, the transaction is rolled back. Examples of use are as follows:
Sqlitedatabase db = ....;    Db.begintransaction ();//Start transaction try {Db.execsql ("INSERT into person (name, age) VALUES (?,?)", New object[]{"Preach Wisdom Podcast", 4}); Db.execsql ("Update person set name=?")    Where personid=? ", New object[]{" Preach Wisdom ", 1}); Db.settransactionsuccessful ();//Call this method to commit the current transaction when it executes to endtransaction (), and if this method is not called, rollback the transaction} finally {db.endtransaction ();// The flag of the transaction determines whether to commit the transaction or rollback the transaction} db.close (); The above two SQL statements are executed in the same transaction. L
Related Article

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.