Recently while trying come delete certain rows native a table using JPA query and also Native query, ns have obtained java.sql.SQLException. The errors state that :java.sql.SQLException: can not issue data manipulation statements through executeQuery().

You are watching: Can not issue data manipulation statements with executequery().


*

Although the error message is pretty lot self explanatory. Let me display you the repository class and share the used tech stack climate it would offer you the appropriate context.Tech Stack:
- HikariCPNote:
spring-boot-starter-data-jpa includes "tomcat-jdbc" together it"s interior dependency. Wondering exactly how am I making use of HikariCP then . Watch <1>.

package com.anshulsblog.service.employee.datalayer.repository;import org.springframework.data.jpa.repository.Query;import org.springframework.data.repository.CrudRepository;import org.springframework.data.repository.query.Param;import org.springframework.data.rest.core.annotation.RepositoryRestResource;import org.springframework.transaction.annotation.Transactional;import com.anshulsblog.service.employee.entity.Employee;
Now you watch my Repository class and the error, it"s apparent that within EntityManager is usingexecuteQuery()
method come execute the SQL statements. That"s why it"s functioning for choose statement but not for DELETE statement. I have additionally tried to INSERT a dummy data using indigenous query just to check but it has given me the same error.
Query(nativeQuery = true, value = "INSERT right into `employee` VALUES(1,"Anshul Agrawal","India")" )public void tryInsert();
We all know thatexecuteQuery()
method is provided to execute SQL statements i beg your pardon retrieves part data indigenous database vice versa, executeUpdate() and execute() technique is used to execute SQL declaration which update or modify the database. But here we are not manually executing these methods thus I thought there have to be part out of crate solution listed by spring-data module as a convention.

See more: Fallout 4 Clothing That Can Be Worn Under Armor, Fallout 4 Armor And Clothing

Solution
Modifying
annotation come the repository technique then one could also execute DML statements prefer DELETE, INSERT or UPDATE. This annotation would cause the query annotated come the technique as update query rather of a choosing one. We have other solution additionally like one could administer custom implementation for your Spring Data repositories. So now our techniques becomes:
Appendix<1> - excluded tomcat-jdbc
native spring-boot-starter-data-jpa, currently by default Spring boot will use HikariCP .Happy Learning!! :-)
Posted byAnshul Agrawalat6:23 PM

*
*

*
This job-related by Anshul Kumar Agrawal is license is granted under a an innovative Commons Attribution-NonCommercial-NoDerivatives 4.0 worldwide License.
►  2020(1) ►  2019(14) ▼  2018(14) ▼  March(2) ►  2017(31) ►  2016(4)
Application ServerBloggerCentOSChecked ExceptionDevOpsEnclosure LinksEPELExceptionFeedBurnerHow ToHreflangJavaJump BreakLinuxRHELSearch Engines(Google)SELinuxSELinux ModestarTomcatVagrantVirtualBoxVirtualizationWeb ServerYUM
*
*
Redmi 6 (Black, 32 GB)
*