Back to project page DataPersistence.
The source code is released under:
Apache License
If you think the Android project DataPersistence listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.datapersistencedemo; // w w w . j av a2s . c o m import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class MyDatabaseHelp extends SQLiteOpenHelper { public static final String CREATE_USER = "create table User (" +"id integer primary key autoincrement," +" account text, " +" password text, " +" phone text) "; public static final String CREATE_BOOK = "create table Book (" +"id integer primary key autoincrement," +" author text, " +" bookname text, " +" pages integer, " +" price real, " + "account text) "; //????book?????????????????????????????????????? private Context mContext; public MyDatabaseHelp(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); mContext = context; } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_USER); db.execSQL(CREATE_BOOK); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { switch (oldVersion) { //??????????????book???????????????????????????user??. //??????break;????????????????????????????????????????????????????? case 1: db.execSQL(CREATE_USER); case 2: db.execSQL("alter table book add column account text"); default: break; } } }