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