简体   繁体   中英

Import csv file to populate data in a table in Netbeans

I am very new to Java and Netbeans.I am trying to populate my table created in my database with data but the csv file contains about 1000 odd entries.Is there a way in which i can just import the data to their columns.

Any help would be appreciated.

I am assuming that you are using JavaDB that comes bundled with Netbeans (to be more accurate: it's included with the JDK).

You can use the import table command: SYSCS_UTIL.SYSCS_IMPORT_TABLE .
Check: https://db.apache.org/derby/docs/10.1/ref/rrefimportproc.html .

As an example:

  • go here: http://www.andrewpatton.com/countrylist.html and download Country List downloadable as CSV .

  • create a table which you can name COUNTRY and as columns the names in the first line of the downloaded csv file. First column name: SortOrder should be the primary key. Add the rest columns as VarChar columns with size 100. Do the same for the rest but be careful not to mess with the order of the columns as you cannot change it later. What I mean is that the order of the columns that you create in your table, should follow the order of the columns in the csv file. For example "Sort Order" should be created first, then create,"Common Name", then "Formal Name" ....

添加列

  • then remove the first line from the csv file (the column names)

  • execute the following command CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (null,'COUNTRY','c:\\countrylist.csv',',','"',null,0);

  • select the table that you created , right click it and click View data .

Thats it !

If you are using MySQL check:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM