mardi 15 décembre 2015

SQLITE Android : Why does my query doesn't work? (rawQuery)

I'm really glad if you can answer my question. can u see my query down there? whats wrong with that? every time i run the app, it stopped. but when i'm not call the getBusRoute() method it work properly. help me guys enter image description here

public class GreenDataSource{

Context mContext;
GreenSQLiteHelper mGreenSQLiteHelper;

public GreenDataSource(Context context){
    mContext = context;
    mGreenSQLiteHelper = new GreenSQLiteHelper(context);
    SQLiteDatabase database = mGreenSQLiteHelper.getReadableDatabase();
    database.close();
}

  public Cursor getBusRoute(){
        SQLiteDatabase database = read();


        String select = "SELECT BUS_ROUTE.SHELTER_ID, NAMA FROM SHELTER, BUS_ROUTE WHERE BUS_ROUTE.SHELTER_ID = SHELTER.SHELTER_ID";

        Cursor cursor = database.rawQuery(select,null);

        return cursor;
    }
}

And here's how i run the function in fragment

 List<String> busrute = new ArrayList<String>();
                Cursor cursor1 = myDb.getBusRoute();

            if(cursor1.moveToFirst()) {
                do {
                    if (idBus == cursor1.getInt(0)) {
                        busrute.add(cursor1.getString(2));
                    }
                }
                while (cursor1.moveToNext());
            }

Aucun commentaire:

Enregistrer un commentaire