23456789101112131415161718192021222324252627282930313233343536373839404142434445464748package net.macdidi.myandroidtutorial; Import Android.content.context;import Android.database.sqlite.sqlitedatabase;import Android.database.sqlite.sqlitedatabase.cursorfactory;import Android.database.sqlite.SQLiteOpenHelper; public class Mydbhelper extends Sqliteopenhelper {//Repository name public static final String database_name = "MYDATA.DB"; Repository version, when the information structure is changed to change this number, usually plus a public static final int VERSION = 1; Information Library object, fixed linked fields bit change private static sqlitedatabase database; The construction of the structure, in general should not need to modify the public mydbhelper (context context, String name, Cursorfactory factory, int version) { Super (context, name, Factory, version); }//The component that needs the repository call this method, this method does not need to modify the public static Sqlitedatabase Getdatabase (context context) {if (databas E = = NULL | | !database.isopen ()) {database = new Mydbhelper (context, database_name, NULL, VersioN). Getwritabledatabase (); } return database; } @Override public void OnCreate (Sqlitedatabase db) {//To build the form required by the application//to finish it later @Override public void Onupgrade (sqlitedatabase db, int oldversion, int newversion) {//delete the original table//will be back to finish it later Call OnCreate to build a new version of Form onCreate (db); } }
Androu Tutorial (4): SQLite build Repository