赞
踩
import android.annotation.SuppressLint; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; @SuppressLint("DefaultLocale") public class UserDBHelper extends SQLiteOpenHelper { private static final String TAG = "UserDBHelper"; private static final String DB_NAME = "user.db"; // 数据库的名称 private static final int DB_VERSION = 1; // 数据库的版本号 private static UserDBHelper mHelper = null; // 数据库帮助器的实例 private SQLiteDatabase mDB = null; // 数据库的实例 public static final String TABLE_NAME = "user_info"; // 表的名称 private UserDBHelper(Context context) { super(context, DB_NAME, null, DB_VERSION); } private UserDBHelper(Context context, int version) { super(context, DB_NAME, null, version); } // 利用单例模式获取数据库帮助器的唯一实例 public static UserDBHelper getInstance(Context context, int version) { if (version > 0 && mHelper == null) { mHelper = new UserDBHelper(context, version); } else if (mHelper == null) { Log.i("@@@","gouzao2"); mHelper = new UserDBHelper(context); } return mHelper; } // 打开数据库的读连接 public SQLiteDatabase openReadLink() { if (mDB == null || !mDB.isOpen()) { mDB = mHelper.getReadableDatabase(); } return mDB; } // 打开数据库的写连接 public SQLiteDatabase openWriteLink() { if (mDB == null || !mDB.isOpen()) { mDB = mHelper.getWritableDatabase(); } return mDB; } // 关闭数据库连接 public void closeLink() { if (mDB != null && mDB.isOpen()) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。