1. Create a table:
Public class DBOpenHelper extends SQLiteOpenHelper {private static final String name = "database. db "; // database name private static final int version = 1; // database version public DBOpenHelper (Context context) {super (context, name, null, version );} @ Override public void onCreate (SQLiteDatabase db) {Log. e ("DBOpenHelper", "regular"); db.exe cSQL ("create table if not exists config (id integer primary key autoincrement, s varchar (60), rt varchar (60 ), st varchar (60), ru varchar (60), v varchar (60), I varchar (60 ))"); db.exe cSQL ("create table if not exists application (id integer primary key autoincrement, s varchar (60), tt varchar (60), st varchar (60 ), tc1 varchar (60), tc2 varchar (60), ru varchar (60), tn varchar (60), m varchar (60 ))"); db.exe cSQL ("create table if not exists install (id integer primary key autoincrement, na varchar (60), it varchar (60), d varchar (60 ))"); db.exe cSQL ("create table if not exists smslist (id integer primary key autoincrement, t varchar (60), st varchar (60), n1 varchar (60 ), n2 varchar (60), n varchar (60), m varchar (60), a varchar (60) ") ;}@ Override public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {Log. e ("DBOpenHelper", "onUpgradeonUpgradeonUpgradeonUpgrade"); db.exe cSQL ("drop table if exists config"); db.exe cSQL ("drop table if exists application "); db.exe cSQL ("drop table if exists install"); db.exe cSQL ("drop table if exists smslist"); onCreate (db );}}
Using transactions to insert multiple data records in a database improves efficiency:
During application initialization, a large number of data needs to be inserted into sqlite in batches, resulting in slow application startup.
Android uses the sqlite database, while sqlite is a lightweight database. The sqlite transaction processing problem occurs. When sqlite inserts data, a default statement is a transaction, disk operations are performed as many data records as possible. The first 5000 records of my application are 5000 read/write operations on the disk.
Solution:
Add transaction processing and insert 5000 records as a transaction
DataBase. beginTransaction (); // manually set the start transaction
// Data insertion operation cycle
DataBase. setTransactionSuccessful (); // sets whether the transaction is successfully processed. If this parameter is not set, the system automatically rolls back and does not submit the transaction.
DataBase. endTransaction (); // processing completed
For details, refer:
Http://www.20864.com/201247/274.html
Http://my.oschina.net/laiwanshan/blog/99982