Я делаю пакетную обработку с помощью пружинной партии. Во-первых, он читает файл CSV, после чего я хочу обновить базу данных, для этого я использую хранимую процедуру для выполнения различных действий в строке. Код такой:
Reader:
@Bean
@StepScope
public ItemReader<Comprobante> csvFileReader( @Value("#{jobParameters['filename']}") String filename) throws UnexpectedInputException, ParseException{
FlatFileItemReader<Comprobante> reader = new FlatFileItemReader<>();
reader.setResource(new FileSystemResource(fileDir + filename));
reader.setName("CSV-Reader");
reader.setLinesToSkip(1);
reader.setLineMapper(lineMapper());
reader.open(new ExecutionContext());
return reader;
}
@Bean
public LineMapper<Comprobante> lineMapper() {
DefaultLineMapper<Comprobante> defaultLineMapper = new DefaultLineMapper<>();
DelimitedLineTokenizer delimitedLineTokenizer = new DelimitedLineTokenizer();
delimitedLineTokenizer.setDelimiter(",");
delimitedLineTokenizer.setStrict(false);
delimitedLineTokenizer.setNames(new String[] {"cid", "ruc", "tipo", "serie", "numero","fecha", "monto"});
BeanWrapperFieldSetMapper<Comprobante> beanWrapperFieldSetMapper = new BeanWrapperFieldSetMapper<>();
beanWrapperFieldSetMapper.setTargetType(Comprobante.class);
defaultLineMapper.setLineTokenizer(delimitedLineTokenizer);
defaultLineMapper.setFieldSetMapper(beanWrapperFieldSetMapper);
return defaultLineMapper;
}
Writer:
@Bean
public ItemWriter<Comprobante> csvFileWrite (DataSource dataSource, NamedParameterJdbcTemplate jdbcTemplate){
JdbcBatchItemWriter<Comprobante> writer = new JdbcBatchItemWriter<>();
writer.setDataSource(dataSource);
writer.setJdbcTemplate(jdbcTemplate);
writer.setSql("select validateVoucher(? , ?);"); // This is the code with error.
ItemPreparedStatementSetter<Comprobante> valueSetter = new comprobantePreparedStatementSetter();
writer.setItemPreparedStatementSetter(valueSetter);
return writer;
}
Журнал показывает это сообщение:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [select validateVoucher(? , ?);]; nested exception is java.sql.BatchUpdateException: Batch entry 0 select validateVoucher('40883884' , '0') was aborted: ERROR: function validatevoucher(character varying, character varying) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Position: 8 Call getNextException to see other errors in the batch.
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1444) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:632) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:646) ~[spring-jdbc-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
.......