dimanche 1 mai 2016

SQLite querring two rows simultaneously and storing the data in one String

lets say I have a SQLite table like so:

public static final String DataBaseName = "test1.db";
    public static final String DataTableName = "jobsTable";
    public static final String ColID = "ID";
    public static final String ColPlace = "placeName";
    public static final String ColPosition = "position";
    public static final String ColStartingTime = "startingTime";
    public static final String ColHours = "hours";
    public static final String ColAddress = "address";
    public static final String ColPhoneNumber = "phoneNumber";

I already know how to write a query for one row and store the values inside an ArrayList. Bellow code gets all the members of the placeName colum and stores them in an arraylist. e.g. "placename1","placeName2","placeName3","placeName4",...

public ArrayList<String> getAllPlacesNames() {
        SQLiteDatabase db = this.getWritableDatabase();
        Cursor result = db.rawQuery("select placeName FROM " + DataTableName,null);
        ArrayList<String> companyNames = new ArrayList<String>();
        while(result.moveToNext()) {
            String places = result.getString(result.getColumnIndex("placeName"));
            companyNames.add(places);
        }
        return companyNames;
    }

I'm trying to write a method like above that gets the values from two columns (PlaceName and position) and store them like:

"placeName1/position1","placeName2/position2","placeName3/position3","placeName4/position4",...

How can this be done? thank you

Aucun commentaire:

Enregistrer un commentaire