The large data processing and simultaneous reading and writing of Android SQLite operation _android

Source: Internet
Author: User
Tags sqlite sqlite database

This paper illustrates the large data processing and simultaneous reading and writing methods of Android SQLite operation. Share to everyone for your reference, specific as follows:

1. Bulk Write

The use of things, the first cache data, and then batch write data, greatly improve the speed

288, direct inset into 7 seconds

8,640, batch writing takes 5-7 seconds

try {
  this.myDataBase.beginTransaction ();//Manually set start transaction for
  (int i = 0; i < objarr.length; i++) {
   this.mydata Base.execsql (Sql[i]);
  This.myDataBase.setTransactionSuccessful (); Set transaction success without setting automatically rollback uncommitted
  Iresult = true;
  return iresult;
} catch (SQLException e) {
  e.printstacktrace ();
  LOG.E ("Log", E.getmessage ());
  return iresult;
} finally {
  this.myDataBase.endTransaction ();//Processing complete
  this.myDataBase.close ();
}

2. Simultaneous reading and writing

SQLite allows 1 to read, write more,

Getreadabledatabase is read (the bottom is to open the write format, then to read-only mode, if the system is low on memory, open read-only mode)

Curse cur, cur before doing the operation (e.g. Movetofirst () ... are just a pointer and do not operate on the database.

Getwritabledatabase for writing

The open mode of the two operation databases is mutually exclusive, and the underlying sync lock is added

More interested readers of Android-related content can view this site: "Android operation SQLite Database Skills Summary", "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", " The activity Operation skill summary of Android programming, the "Android file Operation skill Summary", "Android programming development SD Card Operation method Summary", "Android Development introduction and Advanced Course", "Android Resource Operation skill Summary", " Android View tips Summary and a summary of the use of Android controls

I hope this article will help you with the Android program.

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.