Androu Tutorial (4): SQLite build Repository

Source: Internet
Author: User

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

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.