There is a table with primary key id . The request changes the value of the age field for the user with the specified id.
"UPDATE users SET age =? WHERE id =?" Is it possible to do the same for several requests with a single query, using the array int[] id as the variable being passed?
Update add my work, but perhaps not very correct option. Any tips?
private static String convertToString(int[] ids) { StringBuilder stringBuilder = new StringBuilder(); for (int id : ids) { stringBuilder.append(id).append(", "); } stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length()); return stringBuilder.toString(); } String values = convertToString(new int[]{228, 230, 231}); PreparedStatement ps = connection.prepareStatement("UPDATE users SET age =? WHERE userId = ? AND id IN(" + values + ")");