android中query查询

本文详细解析了SQL查询语句的使用方法,包括URI、projection、selection、selectionArgs和sortOrder参数的含义与应用,通过实例展示了如何进行复杂查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public final Cursor query (Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder)
Parameters

uriThe URI, using the content:// scheme, for the content to retrieve.
projectionA list of which columns to return. Passing null will return all columns, which is inefficient.
selectionA filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URI.
selectionArgsYou may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings.
sortOrderHow to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.

 

URI 也就是要查询的表的 URI;
 
projection :要查询的列
 
selection :也就是一般的Sql语句跟在where后面的条件
 
selectionArgs:跟在where条件后面的 查询条件的值
 
sortOrder: 不多说. 根据字段排序
 
Cursor 返回值 我们可以理解为 一个list集合
 
 
示例 :  表名 sms     有 id  name  gender age address number sessionId 等字段
             
假设要查询 sms表中 name,sessionId字段信息 根据 gender 为 woman 且 number 值为 1022的查询条件来查询
      uri= content://com.feng.jck /sms
     String [] colums = {"name","sessionId"};
    
     query(uri,colums,"gender = ? and number = ? ",new String[]{"woman","1022"},null);
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值