我在尝试使用spring-batch从数据库中获取数据时遇到问题。 我能够正确传递数据源,也测试了连接。但是当我实施spring-batch时。我总是在结果中得到NULL。这是我的读者课程。请支持。
Public class Database {
Logger log = LogManager.getLogger(Database.class.getName());
@Bean
public ItemReader<ReservedMSISDNVo> databaseCsvItemReader(DataSource dataSource) throws Exception {
JdbcPagingItemReader<ReservedMSISDNVo> databaseReader = new JdbcPagingItemReader<ReservedMSISDNVo>();
databaseReader.setDataSource(dataSource);
databaseReader.setPageSize(1);
PagingQueryProvider queryProvider = createQueryProvider(dataSource);
databaseReader.setQueryProvider(queryProvider);
databaseReader.setFetchSize(2);
databaseReader.setRowMapper(new ParameterizedRowMapper<ReservedMSISDNVo>() {
public ReservedMSISDNVo mapRow(ResultSet rs, int rowNum)
throws SQLException {
ReservedMSISDNVo reservedMSISDNVo = new ReservedMSISDNVo();
reservedMSISDNVo.setMSISDN(rs.getString("MOBILE"));
return reservedMSISDNVo;
}
});
return databaseReader;
}
private PagingQueryProvider createQueryProvider(DataSource dataSource) throws Exception {
H2PagingQueryProvider queryProvider = new H2PagingQueryProvider();
String latestDateQuery = "SELECT SNQ_DATE FROM SNQ_POSTPAID";
queryProvider.setSelectClause("select MOBILE");
queryProvider.setFromClause("from NUMBERS_POSTPAID");
queryProvider.setWhereClause("");
queryProvider.setSortKeys(sortByMSISDN());
queryProvider.init(dataSource);
/* Date latestDate = jdbcTemplateObject.queryForObject(latestDateQuery,
new Object[] {}, Date.class);
if (latestDate != null) {
queryProvider.setWhereClause("WHERE RESERVED = 'true' AND INSERT_DATE="+latestDate);
}else{
queryProvider.setWhereClause("WHERE RESERVED = 'true'");
}*/
return queryProvider;
}
private Map<String, Order> sortByMSISDN() {
Map<String, Order> sortConfiguration = new HashMap<>();
sortConfiguration.put("MOBILE", Order.ASCENDING);
return sortConfiguration;
}
}