2016-02-12 39 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

相关问题