Android Database Update--insertion of tens of thousands of data

Source: Internet
Author: User

In real-world situations, it is possible to encounter a table to insert 100,000 data, and such a database update, if in an unusual way, in the Sqliteopenhelper.onupdate () method of continuous execution of SQL statements, then the efficiency is conceivable, May even cause the entire application to crash!

Solution:

In this case, the solution should be to replace the previous database file with a good db file. Of course, someone may have questions about how to write to the Data/data directory. This is really a problem, however, we can store the database in the SD card directory. Of course, the database is stored in the SD card directory, is indeed a compromise of security.

Implementation steps:

  1. Make the DB file, the tool can be navicat for sqlite and so on;
  2. Store the file in the Res/raw directory
  3. In the Sqliteopenhelper.onupdate () method, delete the previous database file
  4. When you call a method such as Sqliteopenhelper.getreadabledatabase () in your code, the Sqliteopenhelper.oncreate () method is called to create the database if the database does not exist.
  5. In the Sqliteopenhelper.oncreate () method, we do not use the usual SQL statement to build a table, where the raw folder directly under the database files copied to the corresponding path.

Summarize:

The above solution can improve the performance of the update database.

Android Database Update--insertion of tens of thousands of data

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.