本文共 6298 字,大约阅读时间需要 20 分钟。
public class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context, String name, CursorFactory cursorFactory, int version) { super(context, name, cursorFactory, version); } @Override public void onCreate(SQLiteDatabase db) { // TODO 创建数据库后,对数据库的操作 } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO 更改数据库版本的操作 } @Override public void onOpen(SQLiteDatabase db) { super.onOpen(db); // TODO 每次成功打开数据库后首先被执行 } } |
ContentValues cv=new ContentValues(); cv.put(Constants.TITLE, "example title"); cv.put(Constants.VALUE, SensorManager.GRAVITY_DEATH_STAR_I); db.insert("mytable", getNullColumnHack(), cv); |
String[] columns={"ID", "inventory"}; String[] parms={"snicklefritz"}; Cursor result=db.query("widgets", columns, "name=?",parms, null, null, null); |
Cursor result=db.rawQuery("SELECT ID, name, inventory FROM mytable"); result.moveToFirst(); while (!result.isAfterLast()) { int id=result.getInt(0); String name=result.getString(1); int inventory=result.getInt(2); // do something useful with these result.moveToNext(); } result.close(); |
转载地址:http://bxtpx.baihongyu.com/