2017-04-12 30 views
0

即時得到這個錯誤:你的SQL語法有錯誤;檢查對應於你的MySQL手冊斷絕

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 ') ON DUPLICATE KEY UPDATE FIRSTIP='83.242.83.190',IP='83.242.83.190',MUTE='0',MU' at line 1 

我的代碼:

 sb.append("INSERT INTO `TOOLS_USERS` VALUES("); 
    sb.append("'%name%',"); 
    sb.append("'%firstip%',"); 
    sb.append("'%ip%',"); 
    sb.append("%mute%,"); 
    sb.append("%mutereason%,"); 
    sb.append("TIME=%time%,"); 
    sb.append(") ON DUPLICATE KEY UPDATE "); 
    sb.append("FIRSTIP='%firstip%',"); 
    sb.append("IP='%ip%',"); 
    sb.append("MUTE=%mute%,"); 
    sb.append("MUTEREASON=%mutereason%;"); 

嘗試 '%mutereason%';但仍然沒有工作和相同的錯誤:v 任何想法? :d

+1

你有一個錯誤的逗號 –

+0

'TIME =%time%'後面還有一個逗號, ' – Barmar

回答

0
sb.append("INSERT INTO `TOOLS_USERS` VALUES("); 
sb.append("'%name%',"); 
sb.append("'%firstip%',"); 
sb.append("'%ip%',"); 
sb.append("%mute%,"); 
sb.append("%mutereason%,"); 
sb.append("TIME=%time%**,**"); <- The error is the following comma. Try to erase it and compile again. 
sb.append(") ON DUPLICATE KEY UPDATE "); 
sb.append("FIRSTIP='%firstip%',"); 
sb.append("IP='%ip%',"); 
sb.append("MUTE=%mute%,"); 
sb.append("MUTEREASON=%mutereason%;"); 

代碼應類似於此:

sb.append("INSERT INTO `TOOLS_USERS` VALUES("); 
sb.append("'%name%',"); 
sb.append("'%firstip%',"); 
sb.append("'%ip%',"); 
sb.append("%mute%,"); 
sb.append("%mutereason%,"); 
sb.append("TIME=%time%"); 
sb.append(") ON DUPLICATE KEY UPDATE "); 
sb.append("FIRSTIP='%firstip%',"); 
sb.append("IP='%ip%',"); 
sb.append("MUTE=%mute%,"); 
sb.append("MUTEREASON=%mutereason%;"); 
0

我刪除它和它仍然顯示錯誤:

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 ') ON DUPLICATE KEY UPDATE FIRSTIP='127.0.0.1',IP='127.0.0.1',MUTE=0,MUTE' at line 1 

我的代碼:

sb.append("INSERT INTO `TOOLS_USERS` VALUES("); 
    sb.append("'%name%',"); 
    sb.append("'%firstip%',"); 
    sb.append("'%ip%',"); 
    sb.append("%mute%,"); 
    sb.append("%mutereason%,"); 
    sb.append(") ON DUPLICATE KEY UPDATE "); 
    sb.append("FIRSTIP='%firstip%',"); 
    sb.append("IP='%ip%',"); 
    sb.append("MUTE=%mute%,"); 
    sb.append("MUTEREASON=%mutereason%;"); 
+0

它發生的原因是你的sql語法是錯誤的。在「ON DUPLICATE KEY UPDATE」之前,您不能使用逗號。 –

相關問題