我正在尝试将信息从excel文件插入到mysql中,我正在使用springbatch excel扩展名来读取文件,但是当尝试插入mysql时出现错误,显然它不发送我共享我的batch.config的信息
@Bean public BeanWrapperFieldSetMapper beanWrapperFieldSetMapper() { BeanWrapperFieldSetMapper fieldSetMapper = new BeanWrapperFieldSetMapper<>(); fieldSetMapper.setPrototypeBeanName("pagare"); return fieldSetMapper; }
@Bean
ItemReader<Pagare> pagareReader() {
PoiItemReader<Pagare> reader = new PoiItemReader<>();
reader.setResource(new ClassPathResource("pagares.xlsx"));
reader.setRowMapper(excelRowMapper());
return reader;
}
private RowMapper<Pagare> excelRowMapper() {
return new RowMapperImpl();
}
@Bean
public BeanPropertyItemSqlParameterSourceProvider<Pagare> beanPropertyItemSqlParameterSourceProvider() {
return new BeanPropertyItemSqlParameterSourceProvider<>();
}
@Bean
public ItemWriter<Pagare> writer(DataSource dataSource,
BeanPropertyItemSqlParameterSourceProvider<Pagare> sqlParameterSourceProvider) {
JdbcBatchItemWriter<Pagare> jdbcBatchItemWriter = new JdbcBatchItemWriter<>();
jdbcBatchItemWriter.setDataSource(dataSource);
jdbcBatchItemWriter.setItemSqlParameterSourceProvider(sqlParameterSourceProvider);
jdbcBatchItemWriter.setSql("insert into pagare(test1,test2,test3,test4,test5,test6,test7,test8) values (:test1, :test2, :test3, :test4, :test5, :test6, :test7, :test8)");
return jdbcBatchItemWriter;
}
@Bean
public Job jobCsvMysql(JobBuilderFactory jobBuilderFactory, Step step) {
return jobBuilderFactory.get("jobCsvMysql").incrementer(new RunIdIncrementer()).flow(step).end().build();
}
@Bean
public Step step1(StepBuilderFactory stepBuilderFactory,
ItemReader<Pagare> pagareReader, ItemWriter<Pagare> writer, ItemProcessor<Pagare, Pagare> processor) {
return stepBuilderFactory.get("step1").<Pagare, Pagare>chunk(10)
.reader(pagareReader).processor(processor).writer(writer).build();
}
org.springframework.dao.DataIntegrityViolationException:PreparedStatementCallback; SQL [插入pagare(test1,test2,test3,test4,test5,test6,test7,test8)值(?,?,?,?,?,?,?,?)] 列“ test2”不能为空;嵌套异常为java.sql.BatchUpdateException:列“ test2”不能为null
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。