List of usage examples for org.springframework.batch.item.database JdbcParameterUtils countParameterPlaceholders
public static int countParameterPlaceholders(String sql, List<String> namedParameterHolder)
sql
. From source file:org.springframework.batch.item.database.JdbcBatchItemWriter.java
/** * Check mandatory properties - there must be a SimpleJdbcTemplate and an SQL statement plus a * parameter source./*from w w w . j a v a 2 s.c o m*/ */ @Override public void afterPropertiesSet() { Assert.notNull(namedParameterJdbcTemplate, "A DataSource or a NamedParameterJdbcTemplate is required."); Assert.notNull(sql, "An SQL statement is required."); List<String> namedParameters = new ArrayList<String>(); parameterCount = JdbcParameterUtils.countParameterPlaceholders(sql, namedParameters); if (namedParameters.size() > 0) { if (parameterCount != namedParameters.size()) { throw new InvalidDataAccessApiUsageException( "You can't use both named parameters and classic \"?\" placeholders: " + sql); } usingNamedParameters = true; } if (!usingNamedParameters) { Assert.notNull(itemPreparedStatementSetter, "Using SQL statement with '?' placeholders requires an ItemPreparedStatementSetter"); } }