java—如何从mysql中的特定列中获取json对象以进行以下查询

7xllpg7q  于 2021-07-04  发布在  Java
关注(0)|答案(0)|浏览(208)

在下面的查询中

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}]}]}]

如何从结果集中获取?

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

上述方法不起作用。
获取之后,我想迭代并执行Assert。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题