2012-03-14 8 views
0

私は、ユーザーが自動的に寄付したかどうかを検出するシステムを作っています。最初に、収集された列が0に設定されているテーブルからレコードを取得します。ここで、ユーザー名は現在のユーザーのユーザー名です。 itemsカラムがあり、その中には、受け取るべきものを含むjsonでエンコードされた配列があります。 json配列を取得するには、getArray関数を文字列として取得するのではなく、getArray関数を使用する必要があります。私はこのエラーを取得していResultSet getArray関数が機能していませんか?

:ここ java.sql.SQLFeatureNotSupportedException

はのgetArrayがないので、それをテストすることはできません、あなたはJSONと間違って何かに気付いた場合、私に知らせて(私のコードです作業)。

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 ..あなたが読むべき – Serhiy

+0

無関係おそらく何かあなたを助けるためにsome1を取得します。https:// WWWを。 owasp.org/index.php/SQL_Injection –

+0

あなたはどのDBを使用していますか、どのDBドライバを使用してアクセスしていますか? java.sql.SQLFeatureNotSupportedExceptionはjdbcドライバの問題を示します – Alex

答えて

1

getArray()は、データベースに格納されたStringを自動的に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

ありがとうございました!これは多くの助けとなりました。 –

関連する問題