Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to bind a list of tuples using Spring JDBCTemplate?

I have some queries like this:

List listOfIntegers = Arrays.asList(new Integer[] {1, 2, 3});
List objects = 
    namedParameterJdbcTemplate.query("select * from bla where id in ( :ids )",
            Collections.singletonMap("ids", listOfIntegers),
            myRowMapper);

This will send this SQL query to the database:

select * from bla where id in ( 1, 2, 3 )

Now I want to send this type of query to the database:

select * from bla where (id,name) in ( (1,'foo'), (2,'bar'), (3,'foobar'))

Do I need to pass a List<List<Object>> to accomplish this? Will it work with Spring JDBCTemplate?

like image 965
Constantino Cronemberger Avatar asked Apr 26 '14 01:04

Constantino Cronemberger


1 Answers

I have debugged Spring code and found that it expects tuples to be provided as Object[], so for it to work with a List it should be a List<Object[]>.

like image 102
Constantino Cronemberger Avatar answered Sep 18 '22 17:09

Constantino Cronemberger