There are times when you want to dynamically create the conditional part of SQL. Specifically, when the value set in the IN clause changes dynamically.
SELECT foo FROM sample_table WHERE bar IN (?, ?, ?, ?, ?); --Here?I want to deal with when the number of
Such SQL is prone to performance issues, but it's often acceptable for small projects. I have an image of a problem that comes when I forget it, and I can write it by using the for statement honestly, but I'd like to write it concisely.
int size = 10; //I want to create?Number of String placeholders = IntStream.range(0, size) .boxed() .map(i -> "?") .collect(Collectors.joining(", ", "(", ")")); System.out.println(placeholders); // (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Personally, if I find an innovative writing style (in each language), I would like to add it.