我想使用来自字符串数组的迭代值替换字符串中的所有特定字符。使用字符串数组中的迭代值替换字符串中的一个字符
String Sample = " Select * from table A where Id = ? or Id = ?";
String [] args = new String[]{"12","14"}
我想替换'?'来自具有args值的样本字符串。 新的字符串应该像
Sample = " Select * from table A where Id = 12 or Id = 14";
任何一个可以帮助我做一些最好的字符串替换Java中
它看起来像你想构造一个SQL查询。这不是如何做到这一点,查询SQL注入(你试图做的事情会容易受到它)。然后查看准备好的语句,以了解如何正确执行此操作。 – tnw
看看'String.replaceFirst' http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replaceFirst(java.lang.String,%20java.lang.String) –
您可以首先生成语句,如下所示:“从表A中选择*,其中Id =”+ args [0] +“或Id =”+ args [1]; – MiKE