【发布时间】:2015-02-19 12:46:44
【问题描述】:
我正在使用以下语法创建一个包含行的 CSV 文件:
writer.append("SomeString");
writer.append(',');
writer.append("SomeValue");
writer.append(',');
writer.append("SomeString");
writer.append(',');
writer.append("SomeValue");
writer.append(',');
writer.append("SomeOtherValue");
writer.append('\n');
然后我尝试使用以下语法将 csv 文件加载到 mysql 中:
String loadFileSQL = "LOAD DATA INFILE '/home/CSV_FILES/"
+ f.getName().substring(0, f.getName().length() - 4)
+ ".csv' "
+ "INTO TABLE counts "
+ "FIELDS TERMINATED BY ',' "
+ "LINES TERMINATED BY '\n' "
+ "(@col1,@col2,@col3,@col4)"
+ "SET pstr=@col1, pcnt=@col2, rstr=@col3, rcnt=@col4;";
但我得到了错误:
java.sql.SQLException: Row 1 was truncated; it contained more data than there were input columns
网上看好像是分隔符问题。我正在使用 Linux ubuntu,所以我尝试通过 \n 和 \r\n 终止,但没有运气。
【问题讨论】: