1

I have to read the headers of the file in order to create a table in a database with the name of the columns specified on the CSV file.

For instance: enter image description here

the program has to create a table on the database like this:

create table csv_ejemplo (
unit varchar(255),
line varchar(255),
total_time varchar(255),
ocurrences varchar(255),
text varchar(255)
);

Finally, I have to iterate over every column and insert that value into the recently created table.

How could I do this? Should I use reflection? I'm confused because I don't know if the database must be created first outside Java (I mean, through SQLite).

I would appreciate any help.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Lucas
  • 919
  • 4
  • 15
  • 32

1 Answers1

0

The SQLite Database can also be created by Java, check this older post.

A CSV-file is normally delimited by some kind of char (like ,), so you would simply read the file line by line (using BufferedReader or something) and then split the line-string up by using the split()-method.

I guess, the first line of your CSV-File contains some informations about the column-names. So, you'll want to take it's informations to create the Database first and then itterate over the rest to get the values.

To insert the values in the Database, I would use a PreparedStatement, as illustrated in the linked topic.

Community
  • 1
  • 1
Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111