本文介绍了使用"LOAD DATA LOCAL INFILE".在Java中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个cvs文件,其架构是,每个字段都用包围,并用分隔,每个元组都是\ n的换行符
I have a cvs file which schema is, every field is surrounded with ", and seperated by , and every tuple is a newline with \n
所以在我的Java文件中,我写了
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);
但是它抛出一个SQLException:
But it throws an SQLException which says:
我的错误是什么?
如果您能帮助我,我将不胜感激.
I would be appreciate if you can help me.
谢谢
推荐答案
哦,我明白了!我没有用'.
Oh I got it ! I didn't surround my path file with '.
新的sql语句应为:
String esquel = " LOAD DATA LOCAL INFILE '" + path +
"' INTO TABLE recommendations " +
" FIELDS TERMINATED BY \',\' ENCLOSED BY \'\"'" +
" LINES TERMINATED BY \'\\n\'";
这篇关于使用"LOAD DATA LOCAL INFILE".在Java中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!