Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to read csv which column length will not fixed client can provide multiple/single csv with diffrent column data to complete single object(java).

suppose one file contain only names and other can have age or other details but i have to make single object of person and insert into table.

What I have tried:

i couldn't success. i tried some basic csvReader/Writter but it doesn't work if csv column isn't fixed.
Posted
Updated 30-May-17 1:55am
v2
Comments
Richard MacCutchan 30-May-17 4:48am    
Sorry, but no one here can guess what your code is doing wrong. And the whole point about CSV files is that the individual fields can be any length.

1 solution

You can have several .csv files with differing lengths, however, there needs to be a way to create a relationship between the files. What you are describing is a simple database, think of each .csv file as a table. How databases make relationships to other tables is through the use of keys. Unique keys are assigned to each new entry to the main table. These keys can be used to cross reference the user to other tables or .csv files.

The example below demonstrates a simple database using keys to tie information together.

Main.csv file
Key,		Name
01,		Bob
02,		Jill
03,		Sam
04,		Mike

BMW.csv file
Key,		Model
02,		i8

Ford.csv File
Key,		Model
03,		Fusion
04,		Focus

Fiat.csv File
Key,		Model
01,		124 Spider

Using the example database, we can create a list of people and what type of car they drive by matching the keys.

Bob, Fiat 124 Spider
Jill, BMW i8
Sam, Ford Fusion
Mike, Ford Focus

Regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900