how to bind a list of tuples using Spring JDBCTemplate?

妖精的绣舞 提交于 2019-12-12 08:01:55

问题


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?


回答1:


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[]>.



来源:https://stackoverflow.com/questions/23305553/how-to-bind-a-list-of-tuples-using-spring-jdbctemplate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!