I want the system to read the csv file in order to analyse the headers and rows of the csv file. The headers of csv file should match with the variables of ProductDetail.java. If the headers matches with these variables, then insert the rows that were read into the database under those headers.
ProductDetail.java
public class ProductDetail {
String street;
String city;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
ReadFile.java
public class ReadFile {
public static void main(String[] args) {
FileReader input = null;
BufferedReader br = null;
try {
input = new FileReader("uploadedFile.csv");
br = new BufferedReader(input);
String str;
while ((str = br.readLine()) != null) {
System.out.println(str);
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
input.close();
br.close();
}
catch (IOException x) {
x.printStackTrace();
}
}
}
}
I have started the project, but now I am quite stuck on how read the columns & rows and match with those predefined headers that are set in ProductDetail.java. It would be great if you can help me on this.