Android 数据存储之 SQLite嵌入式数据库
2010-03-26 15:43:00 来源:WEB开发网contact.get_id() };
this.openHelper.getWritableDatabase().execSQL(sql, bindArgs);
}
/**
* 删除
*
* @param id
*/
public void delete(Integer id) {
String sql = "DELETE FROM contacts WHERE _id=?";
Object[] bindArgs = { id };
this.openHelper.getReadableDatabase().execSQL(sql, bindArgs);
}
/**
* 获取记录数量
*
* @return
*/
public long getCount() {
String sql = "SELECT count(*) FROM contacts";
Cursor cursor = this.openHelper.getReadableDatabase().rawQuery(sql,
null);
cursor.moveToFirst();
return cursor.getLong(0);
}
/**
* 获取分页数据
*
* @param startIndex
* @param maxCount
* @return
*/
public List getScrollData(long startIndex, long maxCount) {
String sql = "SELECT _id,name,phone FROM contacts LIMIT ?,?";
String[] selectionArgs = { String.valueOf(startIndex),
String.valueOf(maxCount) };
Cursor cursor = this.openHelper.getReadableDatabase().rawQuery(sql,
selectionArgs);
List contacts = new ArrayList();
while (cursor.moveToNext()) {
Contact contact = new Contact(cursor.getInt(0),
cursor.getString(1), cursor.getString(2));
contacts.add(contact);
}
return contacts;
}
/**
* 获取分页数据,提供给SimpleCursorAdapter使用。
*
* @param startIndex
* @param maxCount
* @return
*/
public Cursor getScrollDataCursor(long startIndex, long maxCount) {
String sql = "SELECT _id,name,phone FROM contacts LIMIT ?,?";
String[] selectionArgs = { String.valueOf(startIndex),
更多精彩
赞助商链接