All Things Techie With Huge, Unstructured, Intuitive Leaps

MySQL Can not issue data manipulation statements with executeQuery()

Had an interesting MySQL error.  It was:  Can not issue data manipulation statements with executeQuery().

This was the code snippet that caused it:

try {
stmt = conn.createStatement();
myQueryString = "delete from groupnames where id=" + gid;
stmt.executeQuery(myQueryString);

The thing to notice is the query string.  What it was doing, was deleting a record in a table.  It wasn't a query so the line in red is incorrect.

It should have read:

try {
stmt = conn.createStatement();
myQueryString = "delete from groupnames where id=" + gid;
stmt.execute(myQueryString);

Notice that instead of executeQuery, because there is no query in a delete, it should merely read execute.

Hope this helps someone.

No comments:

Post a Comment