Android Open Source - DataPersistence My Database Help






From Project

Back to project page DataPersistence.

License

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.

Java Source Code

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;
    }
  }

}




Java Source Code List

com.example.datapersistencedemo.MainActivity.java
com.example.datapersistencedemo.MyDatabaseHelp.java
com.example.datapersistencedemo.SQLiteActivity.java
com.example.datapersistencedemo.SharedPreferencesActivity.java