2015-05-14 3 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

«база данных» - это зарезервированное слово. Назовите свою таблицу чем-то еще. https://dev.mysql.com/doc/refman/5.5/ru/reserved-words.html – briansol

ответ

Смежные вопросы