Accelerated write to the Android SQLite database

Source: Internet
Author: User
Tags sqlite database

The Android database is written through a transaction at every write, so the consequence is that the speed of writing is super slow, one is near 100ms, then thousands of, no more than two minutes.

To speed up, you have to put all the INSERT statements in one transaction, so the speed is greatly increased.

            Db.begintransaction ();//Start Transaction            try            {                String s = null;                for (int i = 0;i< array.size (); i++)                {                    s = array.get (i);                    Contentvalues contentvalues = new Contentvalues ();                    Contentvalues.put ("P_url", s);                    Contentvalues.put ("P_class", "null");                    Da.getwritabledatabase (). Insert ("P_classification", null,contentvalues);                }                Db.settransactionsuccessful ();//SET transaction does not roll back, if not set then it will be the same as not set the transaction speed            }finally {                db.endtransaction ();//End Transaction Event            }            Db.close ();


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Accelerated write to the Android SQLite database

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.