Java – jdbctemplate in Clause for string element

I use the namedparameterjdbctemplate for clause element, one of which seems to be list < string > Replace them with jdbctemplate (list size) but for in clauses with list < string > It must be '?', '?'

Is there a solution?

Solution

There are other similar questions that may provide you with useful answers:

How to execute IN() SQL queries with Spring’s JDBCTemplate effectivly?

In order for this query method to work in my end, I must switch from the ordinary old JDBC template to namedparameterjdbctemplate

Here are some sample code:

String query = "select * from table where columnName in (:listOfValues)";
List<String> nameRecordIDs = new ArrayList<String>(); 
// ...
// add values to collection,then
// ...
Map namedParameters = Collections.singletonMap("listOfValues",nameRecordIDs);
namedparameterJdbcTemplate.query(query,namedParameters,new MyMapper());
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>