0

What is the best way to import data from few csv files in Spring Batch? I mean one csv file responds to one table in database. I created one batch configuration class for each table and every table has its own job and step. Is there any solution to do this in more elegant way?

1

1 Answer 1

1

There's a variety of ways you could tackle the problem, but the simplest job would look something like:

  • FlatFileItemWriter reader with a DelmitedLineTokenizer and BeanWrapperFieldSetMapper to read the file
  • Processor if you need to do any additional validation/filtering/transformation
  • JDBCBatchItemWriter to insert/update the target table

Here's an example that includes more information around specific dependencies, config, etc. The example uses context file config rather than annotation-based, but it should be sufficient to show you the way.

A more complex solution might be a single job with a partitioned step that scans the input folder for files and, leveraging reference table/schema information, creates a reader/writer step for each file that it finds.

You also may want to consider what to do with the files once you're done... Delete them? Compress them?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.