首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SQLiteOpenHelper 示例

2012-08-22 
【原创】SQLiteOpenHelper 示例package com.firewings.smstoolsimport android.content.Contextimport and

【原创】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) {      }  }  
?

热点排行