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:
- Make the DB file, the tool can be navicat for sqlite and so on;
- Store the file in the Res/raw directory
- In the Sqliteopenhelper.onupdate () method, delete the previous database file
- 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.
- 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