Reputation: 1
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?
Upvotes: 0
Views: 994
Reputation: 3868
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 fileJDBCBatchItemWriter
to insert/update the target tableHere'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?
Upvotes: 1