2012-03-14 51 views
0

我正在制作一个系统来检测用户是否自动捐赠。它首先将收集的列设置为0的表格中的记录以及用户名是当前用户用户名的位置记录下来。有一个项目列,其中是一个json编码数组,其中包含他们应该接收的内容。我需要使用getArray函数来获取json数组,而不是将其作为字符串获取。ResultSet getArray函数不工作?

我得到这个错误: 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(); 
    } 
} 
+0

8个问题和0接受,GL得到some1帮助你.. – Serhiy 2012-03-14 19:54:59

+0

无关,但可能是你应该阅读:https://开头WWW。 owasp.org/index.php/SQL_Injection – 2012-03-14 20:01:46

+0

您正在使用哪种数据库,以及您使用什么数据库驱动程序来访问它? java.sql.SQLFeatureNotSupportedException表示一个jdbc驱动程序问题 – Alex 2012-03-14 21:17:58

回答

1

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

阅读its javadoc

Retrieves the value of the designated column in the current row of this ResultSet object as an Array object in the Java programming language.

Returns: an Array object representing the SQL ARRAY value in the specified column

(重点煤矿)

+0

谢谢!这帮了很多。 – 2012-03-14 23:57:59