Reputation: 1002
I've a List of keys and want to get them in a string with Single quotes and comma separated values..
def keys= [A,B,C,D]
the result should be String values = 'A','B','C','D' as I need to feed these values to groovy.sql query.
Is there a way to do in a simple way to achieve this?
Upvotes: 1
Views: 3407
Reputation: 171054
You mean like:
String s = keys.collect { "'$it'" }.join( ',' )
Be careful though. Escaping your own sql is rarely a good idea, can't you use prepared statements? Or the groovy Sql class? Both of these handle escapes for you
Upvotes: 6