[英]Multiple parameters to SQL JdbcTemplate
I have query like 我有查询
`Select * from Table1 where xyz in (List of String to be Supplied).
In my java code. 在我的Java代码中。 I have a dao object in which I am calling this sql using jdbc template.
我有一个dao对象,在其中使用jdbc模板调用此sql。 The method takes in a list of String and that needs to be supplied to this SQl.
该方法接收字符串列表,并且需要将其提供给该SQ1。 I have my row-mapper.
我有行映射器。
How to write the SQl and how to pass the list of variables? 如何编写SQl以及如何传递变量列表?
My SQL will run on a Teradata Db. 我的SQL将在Teradata Db上运行。
Use a NamedParameterJdbcTemplate which, as the doc says: 使用一个NamedParameterJdbcTemplate ,正如文档所说:
It also allows for expanding a List of values to the appropriate number of placeholders.
它还允许将值列表扩展到适当数量的占位符。
So you just need 所以你只需要
String sql = "select * from Table1 where xyz in :list";
// or String sql = "select * from Table1 where xyz in (:list)";
// I can't remember which one is right
Map parameters = new HashMap<String, Object>();
parameters.put("list", theListOfXyz);
List<Foo> result = template.query(sql, parameters, rowMapper);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.