当前位置: 代码迷 >> SQL >> SQLiteOpenHelper 示例
  详细解决方案

SQLiteOpenHelper 示例

热度:423   发布时间:2016-05-05 14:07:43.0
【原创】SQLiteOpenHelper 示例

package com.firewings.smstools;    import android.content.Context;  import android.database.sqlite.SQLiteDatabase;  import android.database.sqlite.SQLiteOpenHelper;    public class DbHelper extends SQLiteOpenHelper {            private static DbHelper sSingleton = null;        public static final String DATABASE_NAME = "sms.db";      public static final int DATABASE_VERSION = 1;        public interface Tables {          public static final String SMS = "sms";      }        public interface SmsColumns {          public static final String _ID = "_id";          public static final String ADDRESS = "address";          public static final String PERSON = "person";          public static final String DATE = "date";          public static final String TYPE = "type";          public static final String BODY = "body";          public static final String SEND = "send";      }            public static synchronized DbHelper getInstance(Context context) {          if (sSingleton == null) {              sSingleton = new DbHelper(context);          }          return sSingleton;      }        public DbHelper(Context context) {          super(context, DATABASE_NAME, null, DATABASE_VERSION);      }        @Override      public void onCreate(SQLiteDatabase db) {          db.execSQL("CREATE TABLE " + Tables.SMS + " (" +                  SmsColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +                  SmsColumns.ADDRESS + " TEXT NOT NULL," +                  SmsColumns.PERSON + " TEXT," +                  SmsColumns.DATE + " TEXT NOT NULL," +                  SmsColumns.TYPE + " TEXT NOT NULL," +                  SmsColumns.BODY + " TEXT NOT NULL," +                  SmsColumns.SEND + " INTEGER NOT NULL DEFAULT 0" +          ");");      }        @Override      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {      }  }  
?