簡體   English   中英

java.sql.SQLException:第1行被截斷; 它包含的數據多於輸入列

[英]java.sql.SQLException: Row 1 was truncated; it contained more data than there were input columns

我正在使用以下語法創建帶有行的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終止,但是沒有運氣。

我相信您只需要添加@col5 您可以在定義后忽略@col5 ,但該錯誤有效(您的示例有5列,而不是4列)。

"(@col1,@col2,@col3,@col4,@col5)"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM