返回顶部
首页 > 资讯 > 后端开发 > JAVA >Caused by: java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produ
  • 887
分享到

Caused by: java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produ

javasqlissue 2023-09-27 19:09:26 887人浏览 八月长安
摘要

在用Spring Boot JPA的时候, @Query(value = "delete from search_vec where part = ?1 ", native

在用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.

我猜测@Query对应到底层jdbc框架Statement.executeQuery(),而@Modifying@Query对应的是Statement.execute();

来源地址:https://blog.csdn.net/kakadiablo/article/details/128558954

--结束END--

本文标题: Caused by: java.sql.SQLException: Statement.executeQuery() cannot issue statements that do not produ

本文链接: https://lsjlt.com/news/420032.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作