WEB开发网
开发学院手机开发Android 开发 Android 数据存储之 SQLite嵌入式数据库 阅读

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

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),

上一页  1 2 3 4 5 6 7 8 9 10  下一页

Tags:Android 数据 存储

编辑录入:coldstar [复制链接] [打 印]
赞助商链接