将Csv文件导入数据库Mysql

时间:2014-09-13 11:46:26

标签: mysql sql csv

在我的数据库中,我有一个元数据表。在从不同文件中提取元数据后,我在此表中保存了一些数据。

我的表元数据有多列(用于支持所有类型的文件)。 我使用Apache Tika提取metdata并将它们保存在csv文件中。

提取元数据的结果似乎从文件pdf到另一个

示例:

01.pdf
"dcterms:modified","meta:creation-date","meta:save-date","dc:creator","Last-Modified","dcterms:created","Author","date","modified","creator","xmpTPg:NPages","Creation-Date","title","meta:author","created","producer","Content-Type","xmp:CreatorTool","resourceName","Last-Save-Date","dc:title"
"xxxx","xxxx","xxxx","xxxx","xxxx",.... // here the value of metadata

02.pdf // 
"meta:creation-date","dcterms:modified","meta:save-date","dcterms:created","Last-Modified","date","modified","xmpTPg:NPages","Creation-Date","created","producer","Content-Type","xmp:CreatorTool","resourceName","Last-Save-Date"
"xxxx","xxxx","xxxx","xxxx","xxxx",.... // here the value of metadata

01.pdf文件中元数据的标题与02.pdf文件不同。 有不同的顺序!! 我的表元数据为csv文件中的字段提供了更多列。 当我使用这个SQL查询在我的表中插入数据时,某些列不会从csv文件中获取extact值!!

 String sql1="LOAD DATA LOCAL INFILE \'"+FormatStrWithBackSlash(fValueMetadata)+"\' INTO \
            TABLE edocx_metadatafile FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n'IGNORE 1 ROWS \
             (`dcterms:modified`,`meta:creation-date`,`meta:save-date`,`dc:creator`,\
              `Last-Modified`,`dcterms:created`,`Author`,`date`,`modified`,`creator`,`xmpTPg:NPages`,`Creation-Date`,  \
              `title`,`meta:author`,`created`,`producer`,`Content-Type`,`xmp:CreatorTool`,`resourceName`,`Last-Save-Date`,`dc:title`)";

那么,如何正确匹配我的csv文件中的字段与mytable元数据中的列?

0 个答案:

没有答案