0
// 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();
    }

It stops the app. What I doing wrong there?? Is there any mistake in subquery or retrieving??

Muhammad Noman
  • 1,344
  • 1
  • 14
  • 28
  • 1. Post strack trace. 2. Try put apostrophes around your strings, e.g. `IN ('"+source+"')) b1` – Ricky Nov 23 '14 at 14:20

1 Answers1

1

First of all try to quote source and dest by ' symbol like this:

"... WHERE Route IN (\'"+source+"\') ..."

If problem is here then you should think how to avoid this with multiple values in source and dest. In your particular case you should form it correctly like source = "\'1\', \'2\'" or use recommendation from here


P.S. If it doesn't work please provide logcat error message and resulting query (at runtime)

Community
  • 1
  • 1
sberezin
  • 3,266
  • 23
  • 28