简体   繁体   English

导入csv文件以在Netbeans中的表中填充数据

[英]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. 我是Java和Netbeans的新手,我试图用数据填充数据库中创建的表,但csv文件包含约1000个奇数项。有没有一种方法可以将数据导入到它们的列中。

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). 我假设您使用的是Netbeans附带的JavaDB(更准确地说:它包含在JDK中)。

You can use the import table command: SYSCS_UTIL.SYSCS_IMPORT_TABLE . 您可以使用导入表命令: SYSCS_UTIL.SYSCS_IMPORT_TABLE
Check: https://db.apache.org/derby/docs/10.1/ref/rrefimportproc.html . 检查: 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 . 请转到此处: http : //www.andrewpatton.com/countrylist.html并下载可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. 创建一个可以命名为COUNTRY的表,并将已下载的csv文件第一行中的名称作为列。 First column name: SortOrder should be the primary key. 第一列名称:SortOrder应该是主键。 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. 将其余列添加为大小为100的VarChar列。对其余列进行相同操作,但请注意不要弄乱列的顺序,因为以后无法更改。 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. 我的意思是,您在表中创建的列的顺序应遵循csv文件中的列的顺序。 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) 然后从csv文件中删除第一行(列名)

  • execute the following command CALL SYSCS_UTIL.SYSCS_IMPORT_TABLE (null,'COUNTRY','c:\\countrylist.csv',',','"',null,0); 执行以下命令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 . 选择您创建的表,右键单击该表,然后单击“ View data

Thats it ! 而已 !

If you are using MySQL check: 如果您使用的是MySQL,请检查:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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