SQLite 查询:使用 BETWEEN 子句选择查询
我想在 Android 应用程序中运行此查询:
SELECT field1 FROM table1
where field1 = ?(enteredField1) AND field2 = ?(enteredField2)
AND enteredField3 BETWEEN field3 , field4
;
我的数据库架构
table1(field1, field2, field3, field4, field5)
EnteredField1 , 2 , 3 = 是要检查的参数。
我希望我的问题很清楚。
这是函数 -
public boolean checkData(String task1, String dte1, String startTime1 )
{
// field 1 = task , fiels 2 = dte, field 3 = startHr, field 4 = endHr
// enteredField 1,2,3 = task1, dte1, startTime1
// here I want to insert the query
int a = cursor.getCount();
if(a>0)
{
return true;
}
return false;
}
I want to run this query in Android Application :
SELECT field1 FROM table1
where field1 = ?(enteredField1) AND field2 = ?(enteredField2)
AND enteredField3 BETWEEN field3 , field4
;
my DB schema
table1(field1, field2, field3, field4, field5)
enteredField1 , 2 , 3 = are parameters which is to be checked.
I hope I am clear with my question.
here is the function -
public boolean checkData(String task1, String dte1, String startTime1 )
{
// field 1 = task , fiels 2 = dte, field 3 = startHr, field 4 = endHr
// enteredField 1,2,3 = task1, dte1, startTime1
// here I want to insert the query
int a = cursor.getCount();
if(a>0)
{
return true;
}
return false;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您的查询无效。 SQL 中没有
INBETWEEN
; useBETWEEN
:此外,逗号不是在
WHERE
子句中使用的二元运算符;使用AND
代替:使用SQLiteDatabase
中的查询方法。使用哪种取决于您的需要;我链接的那个可能适合你的。First, your query is invalid. There is no
INBETWEEN
in SQL; useBETWEEN
:Also, the comma is not a binary operator that works in
WHERE
clauses; useAND
instead:Execute the query with one of the query methods in
SQLiteDatabase
. Which you use depends on your needs; the one I linked to is probably fine for yours.您可以使用 SQLiteQueryBuilder 来解决您的问题。下面小编给大家带来一个例子,希望对大家有所帮助。
you can use SQLiteQueryBuilder to solve your problem. Following is an example for you, hope it can help.