gpt4 book ai didi

java - 您的 SQL 语法有误;检查与您的 MySQL 服务器版本等对应的手册

转载 作者:行者123 更新时间:2023-11-28 23:37:46 24 4
gpt4 key购买 nike

我有一个简单的表,有 id(autoincrement) 和名称,我正在尝试做一个非常简单的插入查询

if (connect != null) {
query = new StringBuffer("");
query.append("INSERT INTO ");
query.append("GROUP( ");
query.append("GROUP_NAME ");
query.append(") values (");
query.append("?)");
System.out.println(query.toString());
stmt = connect.prepareStatement(query.toString());
int i = 0;
stmt.setString(1, group.getGroupName());
records = stmt.executeUpdate();
}

但它给了我一个堆栈跟踪异常:

2016-02-09T10:00:44.876+0500|Severe: 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 'GROUP( GROUP_NAME ) values ('Hockey')' at line 1

我已经搜索过此类问题,但找不到合适的解决方案。

最佳答案

GROUP 是一个 reserved word在 MySQL 中。

Most of the reserved words in the table are forbidden by standard SQL as column or table names (for example, GROUP).

您最好根本不使用保留字作为标识符,正是出于这个原因。如果绝对必须,请使用反引号 ` 来引用保留字,如 Section 9.2.1 中所述。 MySQL 引用手册。

关于java - 您的 SQL 语法有误;检查与您的 MySQL 服务器版本等对应的手册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35284326/

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