The question is NOT answered in the linked one!
I want to feed an IN
claubse with a List
or Set
of Strings
:
private static final ItemPreparedStatementSetter<MyItem> PREPARED_SETTER = (item, ps) -> {
ps.setObject(1, item.mylist); //being a List<String> or Set<String>
};
PreparedStatement ps = con.prepareStatement("SELECT * FROM mytable where somefield IN (?)");
PREPARED_SETTER.setValues(item, ps);
ps.addBatch();
ps.executeBatch();
Result:
Caused by: java.sql.SQLException: Invalid utf8 character string: 'ACED00'
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readErrorPacket(AbstractQueryProtocol.java:1683)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1545)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1508)
at org.mariadb.jdbc.internal.protocol.AsyncMultiRead.call(AsyncMultiRead.java:132)
... 5 more
The invalid AC ED 00
hint means there is a problem with the object (item.mylist) during serialization.
Question: how can I properly pass a List
or Set
into the IN
clause?