开发学院手机开发Android 开发 Android SQLiteOpenHelper的使用心得 阅读

Android SQLiteOpenHelper的使用心得

 2010-11-05 00:58:43 来源:WEB开发网   
核心提示:DBHelper dbHelper = null; SQLiteDatabase db = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCr
DBHelper dbHelper = null; SQLiteDatabase db = null; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.sqlitetest); OpenDb(); textBtn = (Button)findViewById(R.id.btnHeader); textBtn.setFocusable(true); // btnCreateDb = (Button)findViewById(R.id.btnCreateDb);// btnCreateDb.setOnClickListener(createDbListener);// // btnCreateTb = (Button)findViewById(R.id.btnCreateTb);// btnCreateTb.setOnClickListener(createTbListener); btnInsert = (Button)findViewById(R.id.btnInsert); btnInsert.setOnClickListener(insertTbListener); btnUpdate = (Button)findViewById(R.id.btnUpdate); btnUpdate.setOnClickListener(updateTbListener); btnDelete = (Button)findViewById(R.id.btnDelete); btnDelete.setOnClickListener(deleteTbListener); } public OnClickListener deleteTbListener = new OnClickListener() { public void onClick(View v) { DeleteTb(); } }; public OnClickListener updateTbListener = new OnClickListener() { public void onClick(View v) { UpdateTb(); } }; public OnClickListener insertTbListener = new OnClickListener() { public void onClick(View v) { InsertTb(); } }; // public OnClickListener createDbListener = new OnClickListener() {// public void onClick(View v) {// CreateDatabase("TestDb01");// }// };// public OnClickListener createTbListener = new OnClickListener() {// public void onClick(View v) {// CreateTable();// }// }; // /**// * 新建一个数据库// * @param dbName// * @return// */// public SQLiteDatabase CreateDatabase(String dbName){// dbHelper = new DBHelper(this, dbName);// return dbHelper.getWritableDatabase();// } /** * 新建一个表 * @param db */ public void CreateTable(){ db = dbHelper.getWritableDatabase(); String sql = "create table if not exists TestUsers"+ "(id int primary key,name varchar,sex varchar)"; try { db.execSQL(sql); } catch (SQLException e) { Log.i("err", "create table failed"); } } /** * 插入数据 */ public void InsertTb(){ db = dbHelper.getWritableDatabase();

Tags:Android SQLiteOpenHelper 使用

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接