java - JDBC 准备语句 SQLSyntaxErrorException

标签 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

我尝试在工作台上运行此 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";

关于java - JDBC 准备语句 SQLSyntaxErrorException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31196055/

相关文章:

java - 如何从目录中选择特定的输入文件到Mapreduce程序

java - 使用 LocalDate 将一个日期更改为另一种日期格式

MySQL 优化查询以计算一段时间内的计划项目

java - 在外部主机上运行时缺少 Oracle 数据库连接驱动程序

java - 在java中使用mysql回滚事务

java - 在 while(rset.next) 内调用方法时耗尽结果集

java - SWT webkit 浏览器和 javascript

java - NullPointerException 与 libgdx 使用 gdx render() 方法

sql - 是否可以使用 INSERT 命令将数据插入表的中间部分?

python - pymssql.connect()错误: "adaptive server is unavailable or does not exist"