【发布时间】:2015-01-07 16:55:40
【问题描述】:
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;糟糕的 SQL 语法 [DELETE model_state_history FROM model_state_history INNER JOIN 模型开启 model_state_history.model_id = model.id WHERE model.package_id = ?]; 嵌套异常是 org.h2.jdbc.JdbcSQLException: SQL 中的语法错误 声明“从 [*] 模型状态历史中删除模型状态历史 INNER JOIN 模型 ON model_state_history.model_ID = model.ID WHERE 模型.PACKAGE_ID = ? "; SQL 语句:
它会在输出中抛出上述内容。在我看来,我没有看到语法错误。我正在使用 MySQL 数据库。上面的 SQL 语法有什么明显错误的地方吗?
使用 DELETE FROM 语法也会产生语法错误。
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback;糟糕的 SQL 语法 [DELETE FROM model_state_history INNER JOIN 模型 ON model_state_history.model_id = model.id WHERE model.package_id = ?];嵌套异常是 org.h2.jdbc.JdbcSQLException:SQL 语句中的语法错误“DELETE FROM model_STATE_HISTORY INNER[*] 加入模型 model_STATE_HISTORY.model_ID = model.ID WHERE model.PACKAGE_ID = ? "; SQL 语句:DELETE FROM model_state_history INNER JOIN model ON model_state_history.model_id = model.id WHERE model.package_id = ? [42000-176]
这是正在运行的一段代码
@Transactional
private int deleteAllModels(Long packageId) throws DataAccessException {
return new NamedParameterJdbcTemplate(dataSource).update(
"DELETE FROM model_state_history INNER JOIN model ON model_state_history.version_id = model.id WHERE model.package_id = :package_id",
ImmutableMap.of("package_id", packageId));
【问题讨论】:
-
应该是
DELETE model_state_history FROM model_state_history而不是DELETE FROM model_state_history -
请出示您的代码。
-
@SenthilKumaran 试试
DELETE model_state_history FROM model_state_history ...。看到这个thread