你的SQL语法有错误;检查对应于你的MySQL手册断绝

问题描述:

即时得到这个错误:你的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

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%;"); 

我删除它和它仍然显示错误:

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”之前,您不能使用逗号。 –