Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am passing a Set<string> in my query
but the data is being passed like this :
('[john,ray,mike]')

but I want to pass the data like this in the query:
('john','ray','mike')

How Can I do that?

What I have tried:

This is what I have tried:

SQL
public static ResultSet getData(Set<String> subList) {
		
		String query = "select * from AllRecords in (" + StringUtils.join(subList, ',')+ ") ";

		return DatabaseUtils.getEntries(TestRunner.getCaPostgresConnection(), TestRunner.getSqlStatement(), query);
	}
Posted
Updated 13-Nov-22 21:40pm
v2
Comments
CPallini 14-Nov-22 4:42am    
Instead of using StringUtils.join, write your own function to perform the replacement.
Richard Deeming 15-Nov-22 6:52am    
Not like that! Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation/interpolation to build a SQL query. ALWAYS use a parameterized query.

In this case, that will involve writing a loop to add one parameter for each value to your command object, and appending the parameter names to the command text.

If your custom DatabaseUtils methods don't allow you to use parameters, then throw them out; they are dangerous, and not fit for purpose.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900