纸牌游戏之三

11数据库连接类MyDatabaseHelper类
</pre><pre code_snippet_id="1727164" snippet_file_name="blog_20160623_3_3108055" name="code" class="java">package com.example.azhipai;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

public class MyDatabaseHelper extends SQLiteOpenHelper{
	public static final String CREATE_EXAM="create table exam(id integer primary key autoincrement,name text,examcm integer)";
	private Context mcontext;
	public MyDatabaseHelper(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);
		mcontext=context;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_EXAM);
		Toast.makeText(mcontext, "创建数据库成功", Toast.LENGTH_LONG).show();
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table if exists exam");//删除表若果表存在
		onCreate(db);
	}

}

你可能感兴趣的:(游戏,数据库,sqlite,计算机)