how can i parameter for ArrayList with SQL Template?

9 views
Skip to first unread message

신현기

unread,
May 18, 2022, 3:59:47 AMMay 18
to vert.x
i just tried to put params with ArrayList like this : 
query : 
SELECT id FROM database WHERE id IN(#{idList})

code:
Map<String, Object> tuple = new HashMap<>();
tuple.put("idList", stnidList.toArray(Integer[]::new));
SqlTemplate.forQuery(client, sql).execute(parameters);

but the result Rowset doesn't match with expected
please help :(

Thomas SEGISMONT

unread,
Jun 1, 2022, 3:48:49 PMJun 1
to ve...@googlegroups.com
The IN operator expects a fixed list of parameters. So you must now in advance the number of elements and write your query like this (if you have 3 params):

SELECT id FROM database WHERE id IN(#{id1},#{id2},#{id3})

Otherwise you can use the ANY operator:

SELECT id FROM database WHERE id  = ANY(#{idList})

And then it should work with an arbitrary array

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/5c128bde-6872-449d-83a0-aaaffdd0b5e9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages