package com.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBOpenHelper extends SQLiteOpenHelper {
public DBOpenHelper(Context context) {
//第一个参数上下文对象,第二参数为数据库名,第三迭代结果,第四为版本号
super(context, "dbtest.db", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {//数据库第一次被创建的时候调用
//创建数据库表
db.execSQL("CREATE TABLE person(personid integer primary key autoincrement, name varchar(20), phone VARCHAR(12) NULL)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {//数据库版本号改变才被被调用
// TODO Auto-generated method stub
}
}
//测试类
import com.sqlite.DBOpenHelper;
import android.test.AndroidTestCase;
public class PersonServiceTest extends AndroidTestCase {
public void testCreatDB() throws Exception{
DBOpenHelper dbOpenHelper = new DBOpenHelper(getContext());
dbOpenHelper.getWritableDatabase();
}
}