使用数组来查询SQLite数据库机器人 [英] using an Array to query an sqlite database android

查看:155
本文介绍了使用数组来查询SQLite数据库机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用字符串数组来查询SQLite数据库?我不断收到异常SQliteException:绑定或列索引超出范围。

how can i use an Array of strings to query an sqlite database? i keep getting the exception "SQliteException: bind or column index out of range".

      String[] names = new String[values.size()]; // values is an Arraylist
      String[] condition = values.toArray(names);
Cursor row = db.query(true,DATABASE_TABLE, resultColumns, NAME +"=" + "?", condition, null, null, null,null);

请任何帮助将大大pciated照常AP $ P $。谢谢

please any help will be greatly appreciated as usual. Thanks

P.S值,这是该ArrayList是通过一个循环poplulated,所以我不能有一个定义的大小。这就是为什么我不能使用get()方法,并通过这本来就容易逗号'独立于它的元素。

P.S values, which is the Arraylist is being poplulated through a loop so i can't have a defined size. thats why i can't use the get() method and seperate the elements in it by commas' which would have been easier.

推荐答案

您查询的WHERE子句其中name =?。这预计传入的阵列是大小1.通过其名称来看(名称),我猜它不是。你需要重新思考你希望你的SQL查询来什么(也许,其中名称... )。

Your query's where clause is where name = ?. This expects the passed-in array to be of size 1. Judging by its name (names), I'm guessing its not. You need to rethink what you want your SQL query to be (maybe where name in ...).

例如:

final String whereClause = NAME + " in (" + convertToCommaDelimitedString(values) + ")"; 
db.query(true,DATABASE_TABLE, resultColumns, whereClause, null, null, null, null,null);

您需要执行字符串convertToCommaDelimitedString(集合C);

这篇关于使用数组来查询SQLite数据库机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆