为什么我会收到“MySQLSyntaxErrorException:”错误?

时间:2015-05-14 18:44:20

标签: java mysql sql syntax

语法错误,我似乎无法找到它。我是数据库的新手。

错误:

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;
    }
}

1 个答案:

答案 0 :(得分:3)

DATABASEMySQL reserved word。为表格使用不同的名称