[英]java.sql.SQLException: Row 1 was truncated; it contained more data than there were input columns
I am creating a CSV file with rows using this syntax: 我正在使用以下语法创建带有行的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');
I then try to load the csv files into mysql using this syntax: 然后,我尝试使用以下语法将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;";
But I get the error: 但是我得到了错误:
java.sql.SQLException: Row 1 was truncated; it contained more data than there were input columns
Looking online it seems like a delimiter problem. 在网上寻找似乎是一个定界符问题。 I am using Linux ubuntu so I have tried to terminate by \\n and also \\r\\n with no luck.
我正在使用Linux ubuntu,因此我尝试以\\ n终止,也以\\ r \\ n终止,但是没有运气。
I believe you just need to add @col5
. 我相信您只需要添加
@col5
。 You can ignore @col5
after you define it, but the error is valid (your sample has 5 columns, not 4). 您可以在定义后忽略
@col5
,但该错误有效(您的示例有5列,而不是4列)。
"(@col1,@col2,@col3,@col4,@col5)"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.