Method of inserting Android batch data into SQLite database

In Android, when SQLite inserts data, a statement is a transaction by default. Therefore, if there are tens of thousands of data inserts, tens of thousands of insertion operations need to be performed, and the operation speed can be imagined. Therefore, when inserting data in Android, using batch insertion can greatly improve the insertion speed.

Sometimes some data needs to be built into the application. The following methods are commonly used:

1. Use db.execsql (SQL)

Here is to splice the data to be inserted into executable SQL statements, and then call db.execsql (SQL) to execute the insert.

2. Use dB. Insert ("table_name", null, contentvalues)

This is the encapsulation of the data to be inserted into the ContentValues class, and then the db.insert () method is used to execute the insertion.

3. Using the inserthelper class

This class has been deprecated in API 17

4. Using sqlitestatement

When viewing inserthelper, the official document indicates that the class change has been abandoned. Please use sqlitestatement

The third method takes the shortest time. Since this class has been abandoned in api17, the fourth method should be the best method.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>