gpt4 book ai didi

java - sql语法错误 MySQLSyntaxErrorException

转载 作者:太空宇宙 更新时间:2023-11-03 10:56:31 26 4
gpt4 key购买 nike

String sql = "INSERT INTO order " + "(customerid, pant, shirt, date) " 
+ "VALUES ('" + jTextField1.getText() + "','" + jTextField2.getText()
+ "','" + jTextField3.getText() + "','" + jTextField4.getText() + "')";

当尝试这个时,我得到了以下错误:

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
'order (customerid, pant, shirt, date) VALUES ('10','2','3','26')' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method).

最佳答案

你需要转义reserved words像带反引号的order

INSERT INTO `order` (customerid, ...

除此之外,我建议使用准备好的语句

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

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