开发学院手机开发Android 开发 Android SQLiteDatabase 使用 阅读

Android SQLiteDatabase 使用

 2010-07-01 14:10:00 来源:WEB开发网   
核心提示:+ COUNTRY + " VARCHAR,"+ CODE + " INTEGER)");}public void onUpgrade(SQLiteDatabase db,int oldVersion, int newVersion) {db.execSQL("DROP

+ COUNTRY + " VARCHAR,"

+ CODE + " INTEGER)");

}

public void onUpgrade(SQLiteDatabase db,

int oldVersion, int newVersion) {

db.execSQL("DROP TABLE IF EXISTS "+TB_NAME);

onCreate(db);

}

}

2. 从SQLiteOpenHelper 得到SQLiteDatabase的实例

Java代码

DBHelper helper = new DBHelper(this, DB_NAME, null, VERSION);

SQLiteDatabase db = helper.getWritableDatabase();

DBHelper helper = new DBHelper(this, DB_NAME, null, VERSION);

SQLiteDatabase db = helper.getWritableDatabase();

3. SQLiteDatabase 的一些操作:

* 插入数据:

Java代码

ContentValues values = new ContentValues();

values.put(DBHelper.COUNTRY, "中国");

values.put(DBHelper.CODE, 86);

db.insert(DBHelper.TB_NAME,DBHelper.ID, values);

ContentValues values = new ContentValues();

values.put(DBHelper.COUNTRY, "中国");

values.put(DBHelper.CODE, 86);

db.insert(DBHelper.TB_NAME,DBHelper.ID, values);

* 改动数据

Java代码

db.insert(DBHelper.TB_NAME,DBHelper.ID,null);

values.clear();

values.put(DBHelper.COUNTRY, "意大利");

values.put(DBHelper.CODE, 39);

db.update(DBHelper.TB_NAME, values,DBHelper.ID + " = 2",null);

db.insert(DBHelper.TB_NAME,DBHelper.ID,null);

values.clear();

values.put(DBHelper.COUNTRY, "意大利");

values.put(DBHelper.CODE, 39);

db.update(DBHelper.TB_NAME, values,DBHelper.ID + " = 2",null);

* execSQL 执行SQL语言

Java代码

db.execSQL("INSERT INTO "

+ DBHelper.TB_NAME + "("

+ DBHelper.COUNTRY + ","

+ DBHelper.CODE + ") VALUES "

+ "('洪都拉斯',504)");

db.execSQL("INSERT INTO "

+ DBHelper.TB_NAME + "("

Tags:Android SQLiteDatabase 使用

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