gpt4 book ai didi

mysql - sql 查询在 mysql 中工作正常,但在 HSQL 中失败,并在 spring-boot 测试中出现 BadSqlGrammarException

转载 作者:行者123 更新时间:2023-11-29 17:40:52 26 4
gpt4 key购买 nike

我有一个 spring-boot 服务,我正在编写单元测试。该服务执行以下方法作为 API 的一部分。我通过 Rest Client 手动测试了 API,可以看到它正在工作。

 public int doProessing(String name) {
String sql = "DELETE BS FROM FOO.TABLE1 BS JOIN FOO.TABLE2 BM on BM.SURR_KEY = BS.SURR_KEY WHERE BM.NAME = ?";
return jdbcTemplate.update(sql, new Object[]{StringUtils.upperCase(name)});
}

当我编写使用 HSQL 的单元测试时,出现以下异常。

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [DELETE BS FROM FOO.TABLE1 BS JOIN FOO.TABLE2 BM on BM.SURR_KEY = BS.SURR_KEY WHERE BM.NAME = ?]; nested exception is java.sql.SQLSyntaxErrorException: unexpected token: BS required: FROM in statement [DELETE BS FROM FOO.TABLE1 BS JOIN FOO.TABLE2 BM on BM.SURR_KEY = BS.SURR_KEY WHERE BM.NAME = ?]

我不明白为什么 HSQL 会提示这个在 MySQL 中运行良好的 sql。

谢谢

最佳答案

不支持此操作,因为它使用 JOIN 进行 DELETE。 HSQLDB语法如下:

DELETE FROM FOO.TABLE1 BS WHERE BS.SURR_KEY IN (SELECT BM.SURR_KEY FROM FOO.TABLE2 BM WHERE BM.NAME = ?)

关于mysql - sql 查询在 mysql 中工作正常,但在 HSQL 中失败,并在 spring-boot 测试中出现 BadSqlGrammarException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50014445/

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