-2

Connecting and giving values were very easy ,but I couldn't load the csv data into oracle db

I was able to connect db and give data into db.

But couldn't load csv file which has no header files

  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jan 09 '23 at 11:02
  • When do the headers get added? – K.Nicholas Jan 09 '23 at 13:23
  • Why would you need headers? If you know the structure you know what csv column maps to which db column. You can use Spring Batch with a `FlatFileItemReader` to pump data into the datbase using a `JdbcBatchItemWriter`. You don't even need an intermediate object but could directly stream into the database. If you don't want to use Spring Batch you can simple read the file using an inputstream and use a `JdbcTemplate` with a batch update to insert data. I would ditch OpenCsv and just keep it simple. – M. Deinum Jan 09 '23 at 13:50

1 Answers1

0

Think of it as two separate tasks:

1.Read the csv file:

Create a reader class that transforms lines into entities

YourEntity createEntity(String[] line)

Using the reader process all lines to get a collection of entities corresponding to the csv file

2.Save the entity collection in your JPA repository(DB):

@Repository public interface YourRepository extends JpaRepository<YourEntity, UUID>

yourRepo.saveAll(Iterable entities)