0

In the below query

SELECT grouped_target_tuple FROM targeting_template_target  WHERE targeting_template_id='5863' AND target_id="9906"

[{"childTargets":[{"id":472,"name":"AutoCountry","type":"multiselect","rank":1,"selectedTargetOptions":[{"id":322,"name":"Germany","excluded":false},{"id":323,"name":"Italy","excluded":false}]},{"id":473,"name":"AutoCity","type":"multiselect","rank":2,"selectedTargetOptions":[{"id":324,"name":"Newyork","excluded":false},{"id":325,"name":"NewJersey","excluded":false}]}]}]

How to fetch from the result set?

// Get TT id

        String query = "SELECT grouped_target_tuple FROM targeting_template_target  WHERE targeting_template_id='"
                + ttID + " AND target_id=" + groupedtarID1 + "';";
        ResultSet rs = getInstanceUtilsClass(MySQLUtilities.class).executeQuery(query, dbname);
        ResultSetMetaData rsmd = rs.getMetaData();
        JSONArray array = new JSONArray();
        JSONArray json = new JSONArray();
        while (rs.next()) {
            int numColumns = rsmd.getColumnCount();
            JSONObject obj = new JSONObject();
            for (int i = 1; i <numColumns; i++) {
                String column_name = rsmd.getColumnName(i);
                obj.put(column_name, rs.getObject(column_name));
            }
            json.put(obj);
        }
        BasePage.log(json.toString());
    }

The above is not working.

After I fetch, I want to iterate and perform assertion.

enter image description here

2
  • If the column is a JSON datatype, then you can use rs.getString(column_name). Then you can convert the string to a org.json.JSONObject. Commented Sep 5, 2020 at 19:15
  • Also, it is generally better (safer, and potentially more efficient) to use a prepared statement to build your query, instead of using string concatenation. Commented Sep 5, 2020 at 19:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.