I am fairly new to Java Programming. I have this requirement to Read row of Lines from CSV file (Approximately 25 Column) and load it into MySQL Data Base using JAVA.
The Data has to inserted 1 row at a time , as Multiple Table has to be Inserted or Updated with each row of Data.
I need some mechanism to Map the Header (1st Row in CSV with its corresponding values) , so that in future if i am to add another column in the CSV file , it will not affect my program.
Their might be fields in my CSV file which consist of "," comma as part of field value.
The separator being used is also "," comma.
Any suggestion on where should i start and steps to be followed. I need to perform Multiple Select statement from DB before inserting each row , as few of the Data might already be filled in related Tables and i need to query out the Item ID to insert the Main Record Table.
Lets say if i have the CSV with Four items ,
ProductID , Name , Store Name , Country
101 , Pencil, Evergreen , Finland
So i need to insert these Values into Product Table with Following Schema .
**Product_Table:**
+------------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------+-------+
| Product_ID | varchar(16) | NO | PRI | NULL | |
| Name | varchar(64) | NO | MUL | NULL | |
| Store_ID | int(10) unsigned | NO | | NULL | |
| Country_ID | smallint(5) unsigned | NO | | NULL | |
**Store_Table**
+------------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------+-------+
| Store_ID | varchar(16) | NO | PRI | NULL | AI |
| Name | varchar(64) | NO | MUL | NULL | |
**Country_Table**
+------------------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------+----------------------+------+-----+---------+-------+
| Country_ID | varchar(16) | NO | PRI | NULL | AI |
| Country_Name | varchar(64) | NO | MUL | NULL | |
So as u can see , I need to pass in Store Name and Country Name field value from CSV to get the Corresponding ID (If they exist) , and if they don't then Insert those records first to get the Corresponding ID before Inserting data into Product_Table:
The first loading of CSV will have less than 1000 Records Maximum and the the following loading will only have max 50 records any day. So time is not an issue. The logic and
I was thinking of some logic to store each value from CSV in some variable like
ProductID = ProductID value from CSV
ProductName = Name value from CSV
So that in future, if the order of values in CSV changes , even then i can just use these variable to Insert and query my MYSQL tables schema.