// My getBus Function
Cursor getBus(String source, String dest)
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor cur=db.rawQuery("SELECT b.BusName FROM BusTable b, (SELECT Route , RBusName FROM RouteBusTable WHERE Route IN ("+source+")) b1, (SELECT Route , RBusName FROM RouteBusTable WHERE Route IN ("+dest+")) c WHERE b.BusName IN (b1.RBusName) AND b.BusName IN (c.RBusName)", new String [] {});
return cur;
}
// Retreiving it like this
Cursor a = dbHelper.getBus("1", "12");
a.moveToFirst();
while (!a.isAfterLast())
{
String Name = a.getString(0);
Toast.makeText(AddEmployee.this, "Stops Are "+ Name , Toast.LENGTH_LONG).show();
a.moveToNext();
}
它会停止应用。我做错了什么? 子查询或检索是否有任何错误?
答案 0 :(得分:1)
首先尝试引用source
和dest
以'这样的符号:
"... WHERE Route IN (\'"+source+"\') ..."
如果问题在这里,那么你应该考虑如何在source
和dest
中使用多个值来避免这种情况。
在您的特定情况下,您应该像source = "\'1\', \'2\'"
一样正确地形成它,或者使用here
附:如果它不起作用,请提供logcat错误消息和结果查询(在运行时)