2012-01-16 189 views
-1

我想在Java Web Service的操作中使用JDBC處理MySQL數據庫。 我:JDBC 1064 SQL語法錯誤

stmt = conn.createStatement(); 

String query = "CREATE TABLE Basestations (Network_Id INT," 
        + "Basestation_Id INT, Signal_Strength DOUBLE," 
        + "Frequency DOUBLE, Network_Type VARCHAR(40), Max_Bitrate DOUBLE," 
        + "Guaranteed_Bitrate DOUBLE, Net_Load INT," 
        + "Provider VARCHAR(45), Range DOUBLE, X INT, Y INT," 
        + "Port INT, Charging VARCHAR(40), Active BOOLEAN);"; 

stmt.execute(query); 

創建我的表,但是這會導致:

INFO: SQL Exception: INFO: State : 42000 INFO: Message: 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 'Range DOUBLE, X INT, Y INT,Port INT, Charging VARCHAR(40), Active BOOLEAN)' at line 1 INFO: Error : 1064

什麼是錯我的語法?

回答

1

RANGEreserved keyword is MySQL。相反,圍繞Range`(反向)。

String query = "CREATE TABLE Basestations (Network_Id INT," 
        + "Basestation_Id INT, Signal_Strength DOUBLE," 
        + "Frequency DOUBLE, Network_Type VARCHAR(40), Max_Bitrate DOUBLE," 
        + "Guaranteed_Bitrate DOUBLE, Net_Load INT," 
        + "Provider VARCHAR(45), `Range` DOUBLE, X INT, Y INT," 
        + "Port INT, Charging VARCHAR(40), Active BOOLEAN);"; 
1

RANGE是MySQL reserved word。 使用反引號'`'引用此字段名稱。

+0

我剛纔說過。 – 2012-01-16 09:43:23

+0

我已經在發帖後閱讀了你的答案;)我可以刪除我的答案,或者我們可以讓尼科斯接受你的答案。 – Devart 2012-01-16 09:48:07

+0

很酷。它表明我們的答案是合法的。 :-) – 2012-01-16 09:53:53