0

二重引用符で囲まれた文字列を出力する例を見つけることができますが、String動的にクエリに変数値を入力する必要があります。

たとえば、次のJavaコードを確認してください

public class TestClass {

static String[] array = {"bug", "new Feature"};
public static void main(String args[]){

    for(String string:array){
        String query = "project = TST AND issuetype = " +"\"string\"";
        System.out.println(query+"\n");
    }   
   }
}

このプログラムを実行すると、次のような出力が得られました

project = TST AND issuetype = "string" 
project = TST AND issuetype = "string"

しかし、私は次のような結果が欲しい

project = TST AND issuetype = "bug"
project = TST AND issuetype = "new Feature"

前もって感謝します

4

1 に答える 1

0

You were putting the value string into a String, instead of appending them, try this:

String query = "project = TST AND issuetype = \"" +string + "\"";

If you are passing this query into a database back-end, then you need to be careful to protect yourself from SQL injection.

For example, if one of the values in the array included a double quote, then it would break your query.

于 2013-09-14T13:11:11.380 に答える