I am on java project to import huge amount of data from .csv file to a database. I am interested in understanding what can be the best approach in achieving this.
- Definitely one of the options is to using java application calling stored procedure.
- Second option I can think of is, since we are already using spring, spring-jdbc pair can help us too.
- Currently we are using spring-hibernate pair to get this done at a application level (This is something I presume is not a right approach)
Can you please help me with some thought from other end of spectrum?
Best option is to use native support of the DB while doing bulk operations with huge data. If Oracle then SQL*Loader. If Postgres then they have the COPY command.
If you are looking for Java specific options then below is my preference order
JDBC: use batch operations support but this has a limitation that any failure in the batch operation will short-circuit the entire flow
Hibernate: ORMs are not meant for this. However, you can use StatelessSession and batch configuration together to achieve optimal performance.