2015-05-14 208 views
0

語法錯誤,我似乎無法找到它。我是數據庫新手。爲什麼我會收到「MySQLSyntaxErrorException:」錯誤?

錯誤:

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

'database'是一個保留字。給你的表命名。 https://dev.mysql.com/doc/refman/5.5/en/reserved-words.html – briansol

回答

相關問題