gpt4 book ai didi

java - java中sql字符串中的MYSQL语法错误

转载 作者:行者123 更新时间:2023-11-29 15:37:00 24 4
gpt4 key购买 nike

这是一个在 mysql 命令行中完美运行的代码,但是当我尝试在 java 中执行查询时,它给出了语法错误,不确定出了什么问题。

我已经添加了空格并修改了代码,仍然没有找到解决方案。

String path = selectedfile.getAbsolutePath();
String sql = "LOAD DATA LOCAL INFILE '" + path + "' REPLACE INTO TABLE
temp FIELDS TERMINATED BY ',' ENCLOSED BY '" + '"' + " LINES TERMINATED BY
'\r\n' IGNORE 1 LINES \n" + "
(fname,lname,email,idemployee,statu,@hiredate,idsupervisor,
jobtitle,description,country,site,clockid) "+
"SET hiredate = STR_TO_DATE(@hiredate, '%m/%d/%Y');";

这是java的输出

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 '' IGNORE 1 LINES (fname,lname,email,idemployee,statu,@hiredate,idsupervisor,job' at line 2

最佳答案

大家好,我设法让代码运行,这里的代码可以作为 future 案例的示例:

String sql = "LOAD DATA LOCAL INFILE '" + path + "' REPLACE INTO TABLE temp
\n FIELDS TERMINATED BY ',' \n ENCLOSED BY '" + '"' + "' \n LINES TERMINATED
BY '\\r\\n' \n
IGNORE 1 LINES \n" +
" (fname,lname,email,idemployee,statu,@hiredate,idsupervisor,
jobtitle,description,country,site,clockid) \n"+
"SET hiredate = STR_TO_DATE(@hiredate, '%m/%d/%Y');";

关于java - java中sql字符串中的MYSQL语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58138727/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com