gpt4 book ai didi

java - JDBC 准备语句 SQLSyntaxErrorException

转载 作者:行者123 更新时间:2023-11-29 12:07:41 26 4
gpt4 key购买 nike

我已经阅读了之前与我的查询相关的问题。尝试在现有代码中进行这些更改。但仍然收到此错误。我花了 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com