Home » Java » inner join query for my android application

inner join query for my android application

Posted by: admin June 30, 2018 Leave a comment

Questions:

So I’m making this android application. A page on the application has to display data from 2 different columns in my database it has to collect the data from the workshops table, and the schedules table where the workshopid is equal. I know I have to use an innerjoin on the workshopid, but this doesnt seem to work for me. this is my code right now. i hope someone can help me with my problem.

 private void GetInfo(String eventName, String workshopName) {
    String GetInfo = null;
    String dbResult = "empty";
    dbConnect database = new dbConnect(this);

    try{
        String query = "SELECT workshopid, scedules.workshopid, scedules.starttime, scedules.endtime, workshopname, workshopdesc FROM workshops INNER JOIN scedules ON workshops.workshopid = scedules.workshopid WHERE workshopname = '" + workshopName + "';";
        GetInfo = "?query=" + URLEncoder.encode(query, "UTF-8");
        String link = "https://jackstest.000webhostapp.com/androiddbconnect.php" + GetInfo;
        dbResult = database.execute(link).get();
    }
    catch(Exception e){
        Header.setText("Workshop");
    }

    try{
        JSONArray ja = new JSONArray(dbResult);
        JSONObject jo = null;
        data = new String[ja.length()];
        data2 = new String[ja.length()];

        for (int i = 0;i < 1 ; i++){
            jo = ja.getJSONObject(i);
            data[i] = jo.getString("workshopname");
            data2[i] = jo.getString("workshopdesc");
        }

        Header.setText(data[0]);
        Content.setText(data2[0]);
        Location.setText("Locatie : " + eventName);

    }
    catch(Exception e){
        e.printStackTrace();
    }

content of the workshops table :

workshopid: "1",
workshopname: "Workshop1",
imagelink: "",
workshopdesc: " Lorem ipsum dolor sit amet"

content of the schedules table :

eventid: "1",
workshopid: "1",
starttime: "13:23:00",
endtime: "13:25:00",
date: "2018-04-03"

Out of these 2 tables, from the workshops i need workshopname, workshopdesc, imagelink. And from the schedules table i need the starttime, endtime and date.

Answers: