gpt4 book ai didi

java - 将数据插入 MySQL 表时出错

转载 作者:行者123 更新时间:2023-11-29 13:49:12 25 4
gpt4 key购买 nike

需要帮助..

    Connection cn = DriverManager.getConnection ("jdbc:mysql://localhost/posdb", "root", "");
PreparedStatement dat = cn.prepareStatement("INSERT INTO order VALUES('"+num+"',"+buyamount.elementAt(0)+","+buyamount.elementAt(1)+","+buyamount.elementAt(2)+","+buyamount.elementAt(3)+","+buyamount.elementAt(4)+","+buyamount.elementAt(5)+","+buyamount.elementAt(6)+","+buyamount.elementAt(7)+","+buyamount.elementAt(8)+","+buyamount.elementAt(9)+","+buyamount.elementAt(10)+","+buyamount.elementAt(11)+","+buyamount.elementAt(12)+","+buyamount.elementAt(13)+","+buyamount.elementAt(14)+","+buyamount.elementAt(15)+","+buyamount.elementAt(16)+","+buyamount.elementAt(17)+","+buyamount.elementAt(18)+","+buyamount.elementAt(19)+","+tot+","+tot2+","+(tot2-tot)+")");
System.out.println(dat);
dat.executeUpdate();
cn.close();

错误消息:

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 VALUES('20130605093640',1, 0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,9500,1200' at line 1

num 是字符串,tot 和 tot2 是整数,buyamount 是整数 vector 。

谢谢..任何帮助将不胜感激..

最佳答案

Order 是 MySQL 中的保留字——使用反引号括起来:

INSERT INTO `order`...

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

关于java - 将数据插入 MySQL 表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16930704/

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