Add IN Clause in Prepared Statement using JDBC - madhusudana30/AlternativeJPAForWebSphere GitHub Wiki
Add IN Clause in Prepared Statement using JDBC.
https://stackoverflow.com/questions/3107044/preparedstatement-with-list-of-parameters-in-a-in-clause
javachannel.org/posts/using-sqls-in-in-jdbc/
StringJoiner joiner = new StringJoiner(
",",
"select * from information where info in (",
")");
for (Object ignored : data) {
joiner.add("?");
} String query = joiner.toString(); try (PreparedStatement ps = conn.prepareStatement(query)) {
for (int c = 0; c < data.length; c++) {
ps.setObject(c + 1, data[c]);
}
try (ResultSet rs = ps.executeQuery()) {
showResults(rs);
}
}