Store data from excel file to database using Apache camel

Posted By : Hrishabh Mishra | 30-Jul-2020

ERP

Loading...

Apache Camel:

Apache Camel is a versatile open-source integration framework that enables enterprises to smoothly integrate multiple systems consuming or producing data. Camel allows you to define routing and mediation rules in domain-specific languages, as a Java-based Fluent API, Spring or Blueprint XML Configuration files.

We consume a file from one end point, which is also called route.

from("file:path of file").process(exchange->

File file=exhange.getIn.getbody(File.class);

//. file object contain se path of file like users/local/Desktop.

});

Poiji library is a small library which is developed by ozlerhakan. It gives a way to map java classes from an excel sheet and converts a row of the excel sheet in the list of objects. The columns of excel sheet maps the java pojo classes.

eg. In this example company, model and detail are the columns of the excel sheet, which

is map to java classes.

public class Car {

@ExcelCell(0)

private String Company;

@ExcelCell(1)

private String Model;

@ExcelCell(2)

private String Detail;

@Override

public String toString() {

return "Car [Company=" + Company + ", Model=" + Model + ", Detail=" + Detail + "]";

}

}

----> The index of the excel sheet is accessed by the @ExcelCell annotation.

List<Car> car = Poiji.fromExcel(new File("car.xlsx"), Car.class);

Basically it uses Apache Poi which is the Java API for Microsoft Documents to map processes and read the data of both .xlsx and .xls file.

:- "car" is the instance which stores all the data of the excel file.

When we get the data in a list of objects, then by Jpa operation we save the Data into the database using .save() method in Jpa.

car.size()

car.size() can print the size of the file.

Car car = car.get(0);

This is the type of result we get after debug :-

Car{company='hyundai',model='508',detail='hyundais show room'}.

We use the poji library by adding maven dependency in the pom.xml file in the spring Boot project .

<dependency>

<groupId>com.github.ozlerhakan</groupId>

<artifactId>poiji</artifactId>

<version>3.0.0</version>

</dependency>

Conclusion:

Poiji Library is a best way to store multiple data of excel sheet in a list object having multiple rows and columns .If the data of the excel sheet gets into list object we have an easy way to insert it into the database using Jpa. Poiji uses Apache Poi so it can map multiple columns from the excel sheet into Java pojo classes. It is an excellent way to handle maximum data of excel sheets.

We are a Java Development Company with an objective to provide the best-in-class development services for SaaS models for various software applications and suites. Our services include custom development for CRM, WFMS, HRM, WMS, eCommerce, Finance, and Accounting software for your business. Talk to our experts to find the best software solutions that match your business needs.