ResultSet getArray函数不起作用?

时间:2012-03-14 19:48:35

标签: java sql arrays json

我正在建立一个系统来检测用户是否已自动捐赠。它首先从收集的列设置为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();
    }
}

1 个答案:

答案 0 :(得分:1)

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

阅读its javadoc

  

在Java编程中检索此ResultSet对象的当前行中指定列的值,作为Array对象   语言。

     

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

(强调我的)