I have to create a program in NetBeans that loads 4 .csv files into tables and lets you manage them like a simple database. But I'm not entirely sure how to start. For instance, how do I open the files via jFileChooser so I can even start to operate on them? For now everything I made was text-formed, so I need some help.
3 Answers
I would suggest that you have a look at Spring batch module. what you need is to process the file in a batch
A spring batch consists of the following
- Item reader: Spring supports csvFileReader which will read the conten of the csv file line by line
- Item Processor: The lines read by the reader will be sent to the processor in case we need to perform any business logic on the read lines. If we directly want to save the lines to DB we can skip the processor
- Item Writer: This is used to write the read lines to the DB. You can use hibernate item writer or jdbc item writer to achieve the same.
You can have a look at it here: Spring Batch docs

- 3,154
- 7
- 31
- 51
Break your problem down into simpler parts:
1) Open a text file.
2) Read the contents of the text file, line by line.
3) Parse the lines of the text file as CSV data.
Note that step 2)will be more complex if a "line" of CSV contains line feeds embedded in the data. Probably best to start with a simple CSV file where one line of CSV equates to one line of the file.
You should be able to do 1) and 2) already. Implementing 3) is not difficult, but you need to think things through very carefully. Start with simple data (no embedded quotes of commas) and make sure you have that working correctly before moving on to more complex data with embedded quotes, commas and possibly line feeds.
Simple: "Hello", 3, "123", "World!"
Complex: "Hello, World!", 3,, "123", "He said, \"Hello, World!\""

- 15,344
- 1
- 24
- 38
You can use something like QuickOCM. It is super easy to use. Just create a class that is equivalent to a row in CSV file. It will read the file, convert into list of objects. Now you can do anything with this object easily, use ORM to save to DB or even vanilla JDBC.
you can view the usage here : http://mkhanal.github.io/quickocm/
Input : InputStream
Output : Calls a handler per line in CSV.
Identifies data types like String, BigDecimal, int, etc.
maven :
groupId = io.github.mkhanal
artifactId = quickocm
version = 1.0

- 384
- 3
- 15