Android 在模拟器上显示数据库中提取的信息的列表
2010-11-05 00:56:33 来源:WEB开发网db.execSQL(
"update person set name=?,age=? where personid=?",
new Object[] { person.getName(), person.getAge(),
person.getId() });
}
public Person find(Integer id) {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.rawQuery(
"select personid,name,age from person where personid=?",
new String[] { String.valueOf(id) });
if (cursor.moveToNext()) {
Person person = new Person();
person.setId(cursor.getInt(cursor.getColumnIndex("personid")));
person.setName(cursor.getString(1));
person.setAge(cursor.getInt(2));
return person;
}
cursor.close();
return null;
}
public void delete(Integer id) {
SQLiteDatabase db = databaseHelper.getWritableDatabase();
db.execSQL("delete fro person where personid=?", new Object[] { id });
}
public List< Person> getScrollData(int firstResult, int maxResult) {
List< Person> persons = new ArrayList< Person>();
SQLiteDatabase db = databaseHelper.getReadableDatabase();
Cursor cursor = db.rawQuery(
"select personid,name,age from person limit ?,?",
new String[] { String.valueOf(firstResult),
String.valueOf(maxResult) });// firstResult开始索引
while (cursor.moveToNext()) {// maxResult每页获取的记录数
Log.i("aa", "333333333333");
Person person = new Person();
person.setId(cursor.getInt(cursor.getColumnIndex("personid")));
person.setName(cursor.getString(1));
person.setAge(cursor.getInt(2));
persons.add(person);
}
cursor.close();
return persons;
}
public long getCount() {
SQLiteDatabase db = databaseHelper.getReadableDatabase();
更多精彩
赞助商链接