手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

Android 数据库SQLite Cursor数据遍历读取

时间:2024-10-13 21:49:28

1、通过query获取数据:SQLiteDatabasedataBase=sqliteDB.openDB烫喇霰嘴(); String table="tab_running"; String[] columns={"startaddress","startgpstime","startsystime","endaddress","endgpstime","endsystime"};//你要的数据 String selection="finished=?"; String[] selectionArgs={"1"};//具体的条件,注意要对应条件字段 Cursor cursor=dataBase.query(table, columns, selection, selectionArgs, null, null, null);

2、根据列索引遍历读取列数据:while(cursor.moveToNext()) {//根据列的索引直接读取 比如第0列的值String strValue=cursor.getString(0); }

3、根据列名获取列索引遍历读取列数据:while(cursor.moveToNext()){//根据列名获取列索引 int nameColumnIndex = cursor.getColumnIndex(“username"); String strValue=cursor.getString(nameColumnIndex);}

© 手抄报圈