SQLite transaction processing in Android development, that is, the begintransaction () method...

Source: Internet
Author: User

Use the begintransaction () method of sqlitedatabase to start a transaction. When the program runs to the endtransaction () method, it checks whether the transaction flag is successful. If the program runs to the endtransaction () method () previously, the settransactionsuccessful () method was called to set the transaction flag to successful, then the transaction is committed. If settransactionsuccessful () is not called ()
Method to roll back the transaction. Transaction Processing Applications: in many cases, when we need to insert a large amount of data into SQLite in batches, the use of the add method alone leads to slow application response, because when SQLite inserts data, a default statement is a transaction, and disk operations are performed as many data records as possible. For example, the initial 8000 records mean 8000 read/write operations on the disk. It also aims to ensure data consistency and avoid data loss.

Sqlitedatabase DB = dbopenhelper. getwritabledatabase ();

// Enable transaction dB. begintransaction (); try {// batch processing operation

// Do something db.exe csql ("SQL statement", new object [] {}); db.exe csql ("SQL statement", new object [] {}); // set the transaction flag to successful. When the transaction ends, the transaction dB is committed. settransactionsuccessful ();} catch (exception e ){

}

Finally {// end transaction dB. endtransaction ();}

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.