【问题标题】:Storing the result set in array while fetching from db in java?从java中的db获取时将结果集存储在数组中?
【发布时间】:2021-06-16 17:33:19
【问题描述】:

这是我从列名中的 db 得到的信息

                          data
                  CLONE,CREATE,DELETE

我想在数组中存储类似这样的东西

                    [CLONE,CREATE,DELETE]

这是我正在尝试的,但输出是普通的 JSON 格式

"clone ,create ,delete"

我的代码是这样的

        JSONObject jsonObject = new JSONObject();
            JSONArray array = new JSONArray();
            ResultSet rs = RetrieveData();
            while (rs.next()) {
                JSONObject record = new JSONObject();
                record.put("permissionType", rs.getString("data"));
                array.put(record);
            }
            jsonObject.put("JSON_OBJECT", array);
            try {
                System.out.println(jsonObject);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

【问题讨论】:

    标签: java arrays json list hashmap


    【解决方案1】:

    我认为您需要考虑执行类似rs.getString("data").split(",") 的操作,这将返回使用逗号拆分的字符串数组,即["clone", "create", "delete"]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2010-11-13
      • 2018-03-28
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 2018-07-13
      相关资源
      最近更新 更多