gpt4 book ai didi

java - 为什么会出现 "MySQLSyntaxErrorException:"错误?

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:30 25 4
gpt4 key购买 nike

语法错误,我好像找不到。我是数据库的新手。

错误:

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 'database ( ID INTEGER NOT NULL, QUESTION varchar(100) NOT NULL, ANSWER varchar(5' at line 1

代码:

public void createTable(Connection conn) {
try {
String createString = "CREATE TABLE " + this.tableName + " ( "
+ "ID INTEGER NOT NULL, "
+ "QUESTION varchar(100) NOT NULL, "
+ "ANSWER varchar(500) NOT NULL, " + "PRIMARY KEY (ID))";

this.sendUpdate(conn, createString); //This part definitely works as intended
System.out.println("Created a table called " + this.tableName);
} catch (SQLException e) {
System.out.println("ERROR: Could not create the table");
e.printStackTrace();
return;
}
}

最佳答案

DATABASE 是一个 MySQL reserved word .为表使用不同的名称

关于java - 为什么会出现 "MySQLSyntaxErrorException:"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30244941/

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