2017-04-18 128 views
-3

我想創建一個MySQL表創建MySQL表,我運行此:與Java

statement.executeUpdate("CREATE TABLE IF NOT EXISTS Library (Words, String);"); 

,但我得到了以下錯誤:

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 ' String)' at line 1

+0

'(Words,String)'應該是什麼?兩列?或「字符串」類型的一列?因爲它的錯誤語法是 – khelwood

+0

您需要指定列的類型,例如Words varchar(200)。一個表還應該有一個標識符列,並且字符串不應該被用作其關鍵字 – baao

回答

1

您正在使用的語法不正確,您應該定義列及其數據類型,例如:

CREATE TABLE IF NOT EXISTS Library (Words varchar(255) DEFAULT NULL); 

這意味着將創建Library表的列Words。您可以嘗試在您的語句中使用該語法,例如:

String createTable = "CREATE TABLE IF NOT EXISTS Library (Words varchar(255) DEFAULT NULL)"; 
statement.executeUpdate(createTable);