Sri*_*ish 6 java collections jdbc jdbctemplate
我正在使用NamedParameterJdbcTemplateClause元素和其中一个元素List<String>. JdbcTemplate替换它们?,?,?...(列表大小)但是对于IN子句,List<String>它必须是'?','?'....
有没有解决的办法?
还有一些其他类似的问题,可能会为您提供有用的答案:
如何有效地使用Spring的JDBCTemplate执行IN()SQL查询?
为了使这种查询方式在我的最终工作,我必须从普通的旧JDBCTemplate切换到NamedParameterJdbcTemplate.
这是一些示例代码:
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());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25390 次 |
| 最近记录: |