I have a comma separated string that I need to convert in order to use it in an SQL IN statement e.g SELECT * FROM table WHERE filedvalue IN(conversion)
Below is the method I have come up with so far. The value being passed for Parameter parameter is GBL075,GBL008
public String paramconverter(String parameter)
{
String conversion="";
String newstring="";
String[] parts = parameter.split(",");
for(String part : parts)
{
newstring = newstring.concat("'"+part+"',");
}
conversion = new StringBuilder().append(newstring).toString();
int ind = conversion.lastIndexOf(",");
conversion = new StringBuilder(conversion).delete(ind,ind+1).toString();
System.out.println(conversion);
return conversion;
}
However when I read the console output I get the below results for Variable conversion
'GBL075','GBL008' 'GBL075','GBL008'
This obviously does not work in the sql statement. I need to correct this method and I need assistance. Thanks.