-
You need to use some CSV handling library, like the SuperCSV mentioned earlier or the Apache Common-csv.
-
Your mileage will vary depending on the quality of the CSV data (or the excel table if it from excel). There is no wizard or any other GUI helper to import CSV.
-
I usually make a service, for data import/export. The service home is the core module, so You need to add the maven repository to the core module (in the Project settings, advanced tab). Of course you can do it in GUI module too, and add a the dependency to the GUI module in this case.
-
Beware the import time and memory usage. If the import takes too much time, you will block the GUI thread, and after the import the client will be in disconnected state. To prevent this, long running import must be done in a Background task.
For the background task you wull need some GUI to show to the user, that system is busy. For this there is too possibility:
A. Undetermined progress window, you don’t know how far the process goes, the progress bar will be in undetermined mode (left right movement)
Put such a code in a button event handler or there where You want to start the import:
BackgroundWorkWindow.show(new BackgroundTask<Void, Void>(1200, this) {
@Override
public Void run(TaskLifeCycle<Void> taskLifeCycle) throws Exception {
persistenceService.importCSV(importfile);
return null;
}
}, windowTitle, windowMessage, cancel);
a. 1200 in the 1st line is the max time how long can run the background task, it must be longer than the normal execution time, or you will get a timeout error, and the execution will be aborted.
b. The persistenceService.ImportCSV (importfile) wil lprocess the whole CSV file, record by record.
c. You can specify the Window title in windowTitle, and the progress bar message in the windowMessage parameter. If the cancel parameter is true then you will get a cancel button in the window wher you can cancel the background task.
B. If you know how long itt will takes, then you can use the determined version of this window, but in this case importCSV method must yield the progress to the GUI, and it means that the importCSV method must be aware of such a need.
I prefer to make a general import methods so, the method can be called from several place with GUI or without so I don’t use a determined progresswindow…