简体   繁体   English

Java中的MySQL语法错误

[英]Error with MySQL syntax in java

PreparedStatement sql1 = connection.prepareStatement("UPDATE `bantable` " +
        "SET reason=?, admin=?, started=?, time=?, ends=?, banned=?, datetimes=? " +
        "WHERE DATE_SUB(`datetimes`, NOW())<=0 AND player=?;");
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 'NOW())<=0 AND player='Juustoast''
    at line 1

Why does it print that error? 为什么会显示该错误?

NOW() is just a datetime, so if datetimes also is you can just compare them using normal operators NOW()只是一个日期时间,因此,如果datetimes也是,则可以使用常规运算符进行比较

WHERE datetimes < NOW()

If datetimes is not a datetime , date , or timestamp you will have to convert it. 如果datetimes 不是 datetimedatetimestamp ,则必须对其进行转换。

NOW() is not a time interval, so you couldn't apply DATE_SUB to it. NOW()不是时间间隔,因此您无法对其应用DATE_SUB Use solution proposed in the another answer . 使用另一个答案中提出的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM