public class DBHelper extends SQLiteOpenHelper {
private static final String TAG = "DBHelper";
private static final int DB_VERSION = 1;
private Context context;
private String DB_PATH;
private String DB_NAME;
private String TABLE_NAME;
private boolean booCreate;
private String createString;
private SQLiteDatabase myDataBase;
public DBHelper(Context context, String db_name, String table_name,
boolean booCreate, String createString) {
super(context, db_name, null, DB_VERSION);
this.context = context;
this.DB_NAME = db_name;
this.DB_PATH = "/data/data/" + FindPackageName() + "/databases/";
Log.d(TAG, "DBPATH=" + DB_PATH);
this.TABLE_NAME = table_name;
this.createString = createString;
this.booCreate = booCreate;
Log.d(TAG,"booCreate=" + String.valueOf(this.booCreate));
try {
createDataBase();
} catch (IOException e) {
throw new Error("Unable to Create Database");
}
}
在你的活动中
dbHelper = new DBHelper(this, this.getString(R.string.db_name_contact),
this.getString(R.string.table_name_contacts), true, createString);
观看此视频并从本教程的第三部分下载代码