What is the best approach using JDBC for parameterizing an IN clause? [duplicate]

There’s indeed no straightforward way to do this in JDBC. Some JDBC drivers seem to support PreparedStatement#setArray() on the IN clause. I am only not sure which ones that are. You could just use a helper method with String#join() and Collections#nCopies() to generate the placeholders for IN clause and another helper method to set all … Read more

PreparedStatement with list of parameters in a IN clause [duplicate]

What I do is to add a “?” for each possible value. var stmt = String.format(“select * from test where field in (%s)”, values.stream() .map(v -> “?”) .collect(Collectors.joining(“, “))); Alternative using StringBuilder (which was the original answer 10+ years ago) List values = … StringBuilder builder = new StringBuilder(); for( int i = 0 ; … Read more