【问题标题】:ResultSet getArray function not working?ResultSet getArray 函数不起作用?
【发布时间】:2012-03-14 19:48:35
【问题描述】:

我正在制作一个系统来检测用户是否自动捐款。它首先从一个表中获取记录,其中收集的列设置为 0,并且用户名是当前用户的用户名。有一个 items 列,里面是一个 json 编码的数组,其中包含他们应该接收的内容。我需要使用 getArray 函数来获取 json 数组,而不是作为字符串获取。

我收到此错误: java.sql.SQLFeatureNotSupportedException

这是我的代码(如果您发现 json 有问题,请告诉我,无法测试,因为 getArray 不起作用)。

public void checkForDonation(final Player player) throws JSONException {
    try {
        ResultSet rs = Launcher.getDBC()
                .getQuery(
                        "SELECT * FROM `rewards` WHERE `username`= '"
                                + player.getDisplayName()
                                + "' AND `completed`='0'");
        if (rs.next() == true) {
            JSONArray json = new JSONArray();
            JSONObject obj = new JSONObject();
            try {
                obj.put("items", rs.getArray("items"));
            } catch (org.json.JSONException e) {
                System.err.println(e);
                e.printStackTrace();
            }
            json.put(obj);
            System.out.println(json);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

【问题讨论】:

  • 8 个问题和 0 个被接受,gl 得到一些帮助你..
  • 不相关但可能您应该阅读的内容:owasp.org/index.php/SQL_Injection
  • 您使用的是什么数据库,您使用什么数据库驱动程序来访问它? java.sql.SQLFeatureNotSupportedException 表示 jdbc 驱动程序问题

标签: java sql arrays json


【解决方案1】:

getArray() 绝不是一种将存储在数据库中的字符串自动转换为 JSON 数组的方法。 JDBC 和 JSON 没有任何共同之处。

阅读its javadoc

获取此ResultSet对象当前行中指定列的值作为数组对象在Java编程中 语言。

返回: 一个 Array 对象,表示指定列中的 SQL ARRAY 值

(强调我的)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    • 2021-12-17
    • 2011-05-04
    相关资源
    最近更新 更多