2.获取表中的数据 代码如下:
public List﹤Row﹥ fetchAllRows() {
ArrayList﹤Row﹥ ret = new ArrayList﹤Row﹥();
try {
Cursor c =
db.query(DATABASE_TABLE, new String[] {
"rowid", "title", "body"}, null, null, null, null, null);
int numRows = c.count();
c.first();
for (int i = 0; i ﹤ numRows; ++i) {
Row row = new Row();
row.rowId = c.getLong(0);
row.title = c.getString(1);
row.body = c.getString(2);
ret.add(row);
c.next();
}
} catch (SQLException e) {
Log.e("booga", e.toString());
}
return ret;
}
建立一个游标类Cursor 通过SQLiteDatabase 的query要领
查询一个表格。有了Cursor就可以遍历所有的记录了。 3添加新的记录
public void createRow(String title, String body) {
ContentValues initialValues = new ContentValues();
initialValues.put("title", title);
initialValues.put("body", body);
db.insert(DATABASE_TABLE, null, initialValues);
}
上一篇:C#.Net中的非托管代码清理
下一篇:C#实现动态调用Windows DLL
|