1
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?

4

2 回答 2

0

NOW() is just a datetime, so if datetimes also is you can just compare them using normal operators

WHERE datetimes < NOW()

If datetimes is not a datetime, date, or timestamp you will have to convert it.

于 2013-09-30T19:27:10.743 回答
0

NOW() is not a time interval, so you couldn't apply DATE_SUB to it. Use solution proposed in the another answer.

于 2013-10-02T10:16:33.273 回答