我能够找到用双引号打印字符串的示例,但我需要在动态查询中输入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"
提前致谢
答案 0 :(得分:0)
您将值字符串放入String中,而不是附加它们,请尝试:
String query = "project = TST AND issuetype = \"" +string + "\"";
如果要将此查询传递到数据库后端,那么您需要小心保护自己免受SQL injection的攻击。</ p>
例如,如果数组中的某个值包含双引号,那么它将破坏您的查询。