How can we replace a particular string in existing string in Java?
Example:
String param = "aa,bb,cc";
String str =
"select column_val from table_name where a = '?' and b = '?' and c = '?'";
now i want replace params with its position like..
String newStr =
"select column_val from table_name where a = 'aa' and b = 'bb' and c = 'cc'";
How can we do this? Is there any existing method in stringutil or is there any method to do this?
I suggest you to use StringBuilder. They offer some performance gain in your type of string manipulation, especially if your sql or params are long strings.
Here is an example:
As others have said, remember to sanitize param values to avoid security issues…