JDbcTemplate IN for string elements

Am uses NamedParameterJdbcTemplate for Clause elements, and one of them looks like List<String> . JdbcTemplate replaces them?,?,? ... (list size), but for an IN clause with List<String> it must be '?', '?' ....

Is there any way around this?

+6
source share
1 answer

There are several other similar questions that may give you useful answers:

How to execute IN () SQL queries using JDBCTemplate Spring function?

For this query style to work at my end, I need to switch from the plain old JDBCTemplate to NamedParameterJdbcTemplate .

Here is a 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()); 
+8
source

Source: https://habr.com/ru/post/903680/


All Articles