Android数据库条件查询

Cannot bind argument at index 2 because the index is out of range. The state

碰到这种问题,说明selection参数里面有两个?占位符,selectionArgs数组参数里面没有两个条件参数,导致索引越界

or 跟java中 || 同理,表示查询的mine_type可以是image/jpeg也可以是image/png类型

Cursor cursor = getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "mime_type=? or mime_type=?", new String[]{"image/jpeg", "image/png"},
                null);

还有一个and 跟java中 && 同理,表示查询的mine_type可以是image/jpeg也可以是image/png类型并且时间戳要大于timestamp,因为timestamp是long类型所以不能用占位符?,放到后面的selectionArgs String数组参数中会报错,可以直接拼接在参数selection后面

Cursor cursor = getContentResolver().query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                null,
                "(mime_type=? or mime_type=?) and date_added>"+timestamp,
                new String[]{"image/jpeg", "image/png"},
                null);

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值