gpt4 book ai didi

Mysql插入命令语法

转载 作者:行者123 更新时间:2023-11-29 14:59:27 24 4
gpt4 key购买 nike

我正在使用 MYSQL 5.1,我正在尝试在我的 java 类中编写一条插入语句。听起来很简单,但我尝试了一下并得到了异常(exception)。我确信我的代码存在语法错误。下面是代码片段,任何人都可以帮助我。

  • ID 位于主键中
  • atm_ID 为 varchar
  • trasn_id 是 varchar
  • sysDate 是日期
  • 其余为整数

请帮帮我。

错误:

SQL statement is not executed!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 '£10, £20, £50, £100, trans_Id) VALUES (7,'hello','hello','2','2','2','2','2','he' at line 1`

代码:

String query = "INSERT INTO atm_data (ID,atm_Id, sysDate, availBalance, £10, £20, £50, £100, trans_Id) VALUES (7,'hello','2010-09-15 01:20:06','2','2','2','2','2','hello')";

最佳答案

看起来您只需要转义以 £ 开头并带有反引号的列名称即可:

INSERT INTO atm_data (ID, ... `£10`, `£20`, `£50`, `£100` ...

测试用例:

CREATE TABLE tb (`£10` int);
Query OK, 0 rows affected (0.05 sec)

INSERT INTO tb (£10) VALUES (10);
ERROR 1064 (42000): 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 '?10) VALUES (10)' at line 1

INSERT INTO tb (`£10`) VALUES (10);
Query OK, 1 row affected (0.00 sec)

关于Mysql插入命令语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3653008/

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