Android SQLite database stores multiple data records at a time

Source: Internet
Author: User
Tags sqlite database

During development, a lot of Preset information is often stored in the database at a time. It is a headache for new users.

It is impossible to use the for loop to execute the inert statement once and again. The efficiency is very low. It takes a long time to store 500 pieces of data on the mobile phone.

By searching online materials, there are roughlyThree methods;

1, Through ";" spell string, such as: "insert into table values (x, x, x); insert into table values (x, x, x ); insert into table values (x, x, x );"

2Insert into points (x_axis, y_axis, img_id, width, height) Select 150,150, 40 Union all select 50, 50, 40 Union all select, 50, 40;

3, Import data through XML, and then ...... I looked at this and went straight away.

Conclusion:

For the first method, I successfully simulated it on the computer, but the same statement can only be executed on the Android phone! I tried it many times and had no words. I had to give up.

Method 2Successful. However, if there are many records, you have to write a long statement, but the length is much shorter than that of the first one. ^_^. The experiment I did was to execute 55 pieces of data, which took a short time and could not be affected.

The third method is not tested. The reason is: first, write the records one by one into XML (this workload is not small). The second step is to read the data in XML, and the third step is to insert the data into the database through the second method. The purpose of writing data into XML is to saveCodeSpace. In fact, it is not cost-effective. This method can be used if there is a lot of data, just to save the code space.

If there are other methods, they are stored procedures. However, SQLite does not support complex SQL statements, including stored procedures, or ultra-large-scale data storage.

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.