JDBC PreparedStatement MySQLSyntaxErrorException

JDBC PreparedStatemnt MySQLSyntaxErrorException

我已经阅读了之前与我的 query.Tried 相关的问题,在我现有的 code.But 中进行了这些更改 code.But 仍然得到这个 error.I 已经花了 3 个小时来解决这个问题,但无法赶上bug.Please 帮我解决一下。

我正在使用 PreparedStatement 发送 SQL queries.Below 是查询:

String getExistingFileEntry = "select * from test "
                                    + " where a = ? and b = ? and date < DATE_SUB(NOW(), INTERVAL 1 DAY)"
                                    + "order by id"
                                    + "limit 1";

PreparedStatement pstVerify = null;
            pstVerify = con.prepareStatement(getExistingFileEntry);
            pstVerify.setString(1, a);
            pstVerify.setString(2, b);

            ResultSet rsFirst =null;
            String existingSum = null;
            //execute select SQL statement
                    rsFirst = pstVerify.executeQuery();

收到此错误@rsFirst = pstVerify.executeQuery()

com.mysql.jdbc.exceptions.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 '1' at line 1

我在 workbench 和 returns 上尝试了 运行 这个 SQL 查询的正确行。 有人可以指出我哪里做错了吗?

谢谢!

检查你的空间替换这个

String getExistingFileEntry = "select * from test "
                                    + " where a = ? and b = ? and date < DATE_SUB(NOW(), INTERVAL 1 DAY)"
                                    + "order by id"
                                    + "limit 1";

来自

String getExistingFileEntry = "select * from test "
            + " where a = ? and b = ? and date < DATE_SUB(NOW(), INTERVAL 1 DAY)"
            + " order by id"
            + " limit 1";