JDBC PreparedStatemnt MySQLSyntaxErrorException

时间:2015-07-02 23:08:47

标签: java mysql jdbc prepared-statement

我已经阅读了与我的查询相关的先前问题。请在我现有的代码中进行这些更改。但仍然会收到此错误。我花了3个小时来解决此问题,但无法捕获错误。请帮助我。

我正在使用PreparedStatement发送SQL查询。下面是查询:

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上运行此SQL查询并返回正确的行。 有人可以指出我在哪里做错了吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

检查你的空格替换

'Data.type' does not have a member named 'paths'

通过

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