2017-03-02 40 views
0

我試圖更新MySQL中的表,這是代碼:MySql的更新錯誤的Java

  PreparedStatement ps = con.prepareStatement("UPDATE PbnNumberPlayer SET jointime=?, unique=? WHERE server=?"); 
      ps.setInt(1, jointime); 
      ps.setInt(2, unique); 
      ps.setString(3, name); 

      ps.executeUpdate(); 
      ps.close(); 

,我得到的錯誤是:在查詢原因

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 'unique=0 WHERE server='pbns4'' at line 1 
+0

我們需要查看整個代碼塊以確定問題所在。例如,目前無法理解「jointime」,「unique」或「name」的值。請張貼整段代碼。 – dat3450

+0

也許試試'ps.executeQuery();'而不是'ps.executeUpdate();'。 – dat3450

+0

ps.executeUpdate();是你想要使用的。檢查**名稱**變量的內容。看起來你在那裏有問題。事實上,檢查所有變量的內容。確保它們包含你所期望的。 – DevilsHnd

回答

1

放反引號獨特是mysql中的重要工作

PreparedStatement ps = con.prepareStatement("UPDATE PbnNumberPlayer SET `jointime`=?, `unique`=? WHERE `server`=?"); 

閱讀此處以獲取更多參考here

+1

非常感謝! +1 奇怪的是,我的其他代碼在沒有這些的情況下運行得很完美。但現在,我會添加它們以防萬一。 – Mukri