Android Open Source - sqlite_mod Sqlite Helper






From Project

Back to project page sqlite_mod.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project sqlite_mod 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.zhufeng.sqlite;
//w ww  .ja  va 2 s. co  m
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * 
 * @author Himi
 * @?? ?????????????????? ????????????OK???
 * 
 */
public class SqliteHelper extends SQLiteOpenHelper {
  public final static int VERSION = 1;// ?????
  public final static String TABLE_NAME = "himi";// ????
  public final static String ID = "id";// ??????ContentProvider??
  public final static String TEXT = "text";
  public static final String DATABASE_NAME = "Himi.db";

  public SqliteHelper(Context context) {
    // ?Android ????????????????????openOrCreateDatabase ????????
    // ?????????????????????????????????????????????????
    // ?????????? SQLiteDatabase???????????FileNotFoundException?
    // ????????????????"DATABASE_NAME"????????????SQLiteDatabase??

    super(context, DATABASE_NAME, null, VERSION);
  }

  @Override
  // ???????????????????????????????????????????;
  public void onCreate(SQLiteDatabase db) {
    String str_sql = "CREATE TABLE " + TABLE_NAME + "(" + ID
        + " INTEGER PRIMARY KEY AUTOINCREMENT," + TEXT + " text );";
    // CREATE TABLE ????? ??????????????????
    // ????????????id ?????????,int??
    // PRIMARY KEY ???? ????int?,?????????;
    // AUTOINCREMENT ?????????????????key????????????;
    // ??????????? String??
    // ----------??????str_sql?sql???????dos????????????
    db.execSQL(str_sql);
    // execSQL()?????????sql????
    // ????????????????????????????sql.himi??,
    // ??????? ?????????????????str_sql????sql????????????
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // ??????????????? ????????????
    // ?????????????????Android ?????????????
    // ??????????????????????????????
    // ?????????????????????????????????
    Log.v("Himi", "onUpgrade");
  }
}




Java Source Code List

com.zhufeng.sqlite.SqliteHelper.java
com.zhufeng.sqlite.Sqlite_modActivity.java