如何使用java将数据从CSV文件加载到MySQL表?

时间:2015-07-07 02:02:55

标签: java mysql database

我们需要将客户提供的CSV文件中的数据加载到MySQL表中。我们正在使用以下代码。

LOAD DATA INFILE 'C:/Users/chan/Desktop/gradeschool-student-sorting-app/Output/conertedCSV.csv' INTO TABLE student_temp FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES  TERMINATED BY '\n' IGNORE 1 LINES;

手动加载时,工作正常。但是在通过java执行上述操作时,它会抛出一些例外。

Query: LOAD DATA INFILE C:/Users/chan/Desktop/gradeschool-student-sorting-app/Output/conertedCSV.csv
INTO TABLE student_temp
    FIELDS TERMINATED BY ',' 
    OPTIONALLY ENCLOSED BY '"'
    LINES  TERMINATED BY '\n'
    IGNORE 1 LINES;
Connection successful
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'C:/Users/s521753/Desktop/gradeschool-student-sorting-app/Output/conertedCSV.csv' at line 1
Executed query successfully

0 个答案:

没有答案
相关问题