2016-02-12 86 views
0

我不斷收到SQL語法錯誤,但我無法理解我在哪裏出錯。任何人都可以將我指向正確的方向嗎?SQLSyntaxError即使使用Prepared Statement

String sql = "INSERT INTO Weights" 
      + " (ID, W1, W2, W3, W4, W5)" 
      + " VALUES (?, ?, ?, ?, ?, ?)"; 

    PreparedStatement statement = mysqlConnect.connect().prepareStatement(sql); 
    statement.setString(1, String.valueOf(col-1)); 
    statement.setDouble(2, weights[row][c]); 
    statement.setDouble(3, weights[row][c]); 
    statement.setDouble(4, weights[row][c]); 
    statement.setDouble(5, weights[row][c]); 
    statement.setDouble(6, weights[row][c]); 
    statement.execute(sql); 
+1

總結鏈接重複:你需要使用'statement.execute()'(或'statement.executeUpdate()')來代替。 –

回答

1

您的sql語法已關閉,插入語句爲。

INSERT INTO table (col1, col2, ...) VALUES(v1, v2, ...) 

你基本上缺少一個圓括號,改爲以下。

String sql = "INSERT INTO Weights" 
     + "(ID, W1, W2, W3, W4, W5)" 
     + " VALUES (?, ?, ?, ?, ?, ?)"; 
+0

謝謝!看不見它!我已經解決了這個問題,但我仍然收到錯誤:( – Sfitz12173

+0

SQL語句應該沒問題其他錯誤信息? –

+0

不能在同一行再次發生同樣的錯誤! – Sfitz12173

相關問題