0
我正在編寫一個使用數據庫的應用程序,並且我正在使用一個幫助程序類,有人在此處建議我在stackoverflow中。修改此SQLite幫助類以在數據庫中插入記錄
的輔助類是這個(還需要一個jar文件):https://github.com/jgilfelt/android-sqlite-asset-helper
我將在這裏抄寫它:
public class MyDatabase extends SQLiteAssetHelper {
private static final String DATABASE_NAME = "DB";
private static final int DATABASE_VERSION = 1;
public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public Cursor getItems() {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0 _id", "ItemName", "ItemCategory"};
String sqlTables = "ShopItems";
String selection = "ItemCategory='1'";
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, selection, null,
null, null, null);
c.moveToFirst();
return c;
}
}
這就像一個魅力。但是,我需要添加一個方法來插入新的記錄到表中,我不知道如何做到這一點。有人可以幫助我,還是指向我的鏈接/教程?謝謝
編輯:我不知道它是否有關,但我在資產文件夾上使用預填充的數據庫。
這是一個參考可能會給一些指針http://anujarosha.wordpress.com/2011/12/ 12 /如何對嵌件數據輸入到A-源碼數據庫功能於機器人/ – kosa 2012-02-15 00:53:44