Cannot issue data manipulation statements with executeQuery()
If you're using spring boot, just add an @Modifying annotation.
@Modifying
@Query
(value = "UPDATE user SET middleName = 'Mudd' WHERE id = 1", nativeQuery = true)
void updateMiddleName();
To manipulate data you actually need executeUpdate()
rather than executeQuery()
.
Here's an extract from the executeUpdate()
javadoc which is already an answer at its own:
Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
When executing DML statement , you should use executeUpdate
/execute
rather than executeQuery
.
Here is a brief comparison :