Optimize SQLITE3 Database Insert 1000 data

Source: Internet
Author: User

If you insert 10,000 data into a database in a normal way, will it hinder the user experience? The answer is yes, so how to optimize the various operations of our database.

(1) Use transactions.

String sql = "INSERT into bus_line_station (direct,line_name,sno,station_name) VALUES (?,?,?,?)";        Sqlitestatement stat = db.compilestatement (sql);        Db.begintransaction ();        for (station Line:buslines) {            Stat.bindlong (1, line.direct);            Stat.bindstring (2, line.linename);            Stat.bindlong (3, Line.sno);            Stat.bindstring (4, line.stationname);            Stat.executeinsert ();        }        Db.settransactionsuccessful ();        Db.endtransaction ();        Db.close ();
You can significantly reduce the time it takes to insert a database.

So why? If you are a normal method of inserting a database, inserting 10,000 data needs to execute 10,000 transaction start + Execute sql+ transaction end, and the above transaction start and transaction end only executed once. Most of the time actually executes SQL.

(2) http://blog.csdn.net/hustpzb/article/details/6600591 This doesn't know how to do it.

(3) A thread is opened and a message is sent through handler after performing the operation of inserting the database.


Optimize SQLITE3 Database Insert 1000 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.