Android 数据库SQLite Cursor数据遍历读取
1、通过query获取数据:
SQLiteDatabase dataBase=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);
}
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:174
阅读量:133
阅读量:126
阅读量:117
阅读量:145