If you have objects, you need to map them to ...
Consider smoothing your SQL to match your object field names with a custom RowMapper implementation that actually extends BeanWrapperFieldSetMapper
So, if your POJO looks like this:
public class Employee { private String employeeId; private String employeeName; ...
Then your SQL might look like this:
SELECT emp_id employeeId, emp_name employeeName from employee_table
Then your wrapped RowMapper will look something like this:
import org.springframework.jdbc.core.RowMapper import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper public class BeanWrapperRowMapper<T> extends BeanWrapperFieldSetMapper<T> implements RowMapper<T> { @Override public T mapRow(final ResultSet rs, final int rowNum) throws SQLException { final FieldSet fs = getFieldSet(rs); try { return super.mapFieldSet(fs); } catch (final BindException e) { throw new IllegalArgumentException("Could not bind bean to FieldSet", e); } } private FieldSet getFieldSet(final ResultSet rs) throws SQLException { final ResultSetMetaData metaData = rs.getMetaData(); final int columnCount = metaData.getColumnCount(); final List<String> tokens = new ArrayList<>(); final List<String> names = new ArrayList<>(); for (int i = 1; i <= columnCount; i++) { tokens.add(rs.getString(i)); names.add(metaData.getColumnName(i)); } return new DefaultFieldSet(tokens.toArray(new String[0]), names.toArray(new String[0])); } }
As an alternative...
If you donβt have a POJO to map, use the ready-made ColumnMapRowMapper to get a map ( Map<String,Object> ) of the column names (call them COL_A, COL_B, COL_C) for the values. Then, if your writer is similar to JdbcBatchItemWriter , you can set your named parameters as:
INSERT TO ${schema}.TARGET_TABLE (COL_1, COL_2, COL_3) values (:COL_A, :COL_B, :COL_C)
and then the implementation of ItemSqlParameterSourceProvider might look like this:
public class MapItemSqlParameterSourceProvider implements ItemSqlParameterSourceProvider<Map<String, Object>> { public SqlParameterSource createSqlParameterSource(Map<String, Object> item) { return new MapSqlParameterSource(item); } }