在用Spring Boot JPA的时候,
@Query(value = "delete from search_vec where part = ?1 ", nativeQuery = true)
void dropByPart(int part);
导致异常:
Caused by: java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produce result sets.
解决方法:
在@Query
上加上@Modifying
,表示不需要返回值
@Modifying
@Query(value = "delete from search_vec where part = ?1 ", nativeQuery = true)
void dropByPart(int part);
这是因为,根据Spring data jpa官网
Doing so triggers the query annotated to the method as an updating query instead of a selecting one.文章来源:https://www.toymoban.com/news/detail-532135.html
我猜测@Query
对应到底层jdbc框架是Statement.executeQuery()
,而@Modifying@Query
对应的是Statement.execute();
文章来源地址https://www.toymoban.com/news/detail-532135.html
到了这里,关于Caused by: java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produ的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!