简体   繁体   English

java.sql.SQLException:第1行被截断; 它包含的数据多于输入列

[英]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.

相关问题 java.sql.SQLException:枚举的第1行的列'gender'的数据被截断 - java.sql.SQLException: Data truncated for column 'gender' at row 1 for enum java.sql.SQLException:第 1 行的“MonthlyIncome”列数据被截断错误 - java.sql.SQLException: Data truncated for column 'MonthlyIncome' at row 1 error java.sql.SQLException:为列截断的数据 - java.sql.SQLException: Data truncated for column java.sql.SQLException:子查询返回多于1行 - java.sql.SQLException: Subquery returns more than 1 row java.sql.SQLException: ORA-24335: 不能支持超过 1000 列 - java.sql.SQLException: ORA-24335: cannot support more than 1000 columns 由以下原因引起:java.sql.SQLException:在所有与emailAccess相同的行上,子查询返回的行多于1 - Caused by: java.sql.SQLException: Subquery returns more than 1 row on all rows where emailAccess is thesame 我收到此错误java.sql.SQLException:子查询返回多于1行 - I am getting this error java.sql.SQLException: Subquery returns more than 1 row 获取java.sql.SQLException:没有更多的数据要从套接字读取 - Getting java.sql.SQLException: No more data to read from socket Java和MySQL中的枚举的数据截断(java.sql.SQLException:…的数据截断) - Data truncation for enum in Java and MySQL (java.sql.SQLException: Data truncated for …) JPA-尝试保留Date字段时“ java.sql.SQLException:数据被截断” - JPA - “java.sql.SQLException: Data truncated” when trying to persist Date field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM