1、首先新建一个类DBOpenHelper继承SQLiteOpenHelper然后重写其方法。
类DBOpenHelper
package org.mobiletrain.sqlite_demo4;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
public class DBOpenHelper extends SQLiteOpenHelper{
String sql = "create table if not exists stutb(_id integer primary key autoincrement," +
"name text not null,sex text not null,age integer not null)";
@SuppressLint("NewApi")
public DBOpenHelper(Context context, String name, CursorFactory factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}
public DBOpenHelper(Context context, String name) {
super(context, name, null, 1);
}
//首次创建数据库的时候调用,我们一般把建库或者建表的