I am trying to have this code run and delete a certain record in a MySQL database but I get this error:
SQLException: Can not issue data manipulation stateme
Change
ResultSet rs = statement.executeQuery("DELETE FROM content_resource WHERE RESOURCE_ID LIKE '%Hollow%'");
To
int deletedRows = statement.executeUpdate("DELETE FROM content_resource WHERE RESOURCE_ID LIKE '%Hollow%'");
As others have said, executeQuery() should be used for statements that return data, typically a select statement. For insert / update / delete statements you should use executeUpdate() instead.
Use execute
instead of executeQuery
.
As far as I know, executeQuery
must be used if you are executing a query that returns a resultset (select
for example).
To execute a DML statement (insert, create or delete), you must use executeUpdate()
. Not executeQuery()
.
You use executeUpdate()
for that instead.
executeQuery()
is only for statements that return data. executeUpdate
is for ones that won't return date (update, insert, delete, and I believe things like adding/dropping tables, constraints, triggers, and the like as well).
Use executeUpdate
instead of executeQuery
. JDBC is bummed because the delete statement does not return a record set, as executeQuery
expects.
Ensure that you have set permissions for DELETE
statements. Certain users will have certain commands disallowed for security purposes.