I have a cvs file which schema is, every field is surrounded with ", and seperated by , and every tuple is a newline with \n
So in my Java file, I wrote
String path = "o.csv";
String esquel = " LOAD DATA LOCAL INFILE " + path +
" INTO TABLE recommendations " +
" FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"'" +
" LINES TERMINATED BY \'\\n\'";
And I execute the statement with the following statement
statement.executeUpdate(esquel);
But it throws an SQLException which says:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'o.csv INTO
TABLE recommendations FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES'
at line 1
What is my error ?
I would be appreciate if you can help me.
Thanks
解决方案
Oh I got it ! I didn't surround my path file with '.
New sql statement should be:
String esquel = " LOAD DATA LOCAL INFILE '" + path +
"' INTO TABLE recommendations " +
" FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"'" +
" LINES TERMINATED BY \'\\n\'";