5 messages in com.mysql.lists.javaRe: executeQuery and INSERT / UPDATE ...
FromSent OnAttachments
MacFarland Hale19 Sep 2002 07:09 
MacFarland Hale19 Sep 2002 11:38 
Andrew Houghton19 Sep 2002 11:55 
Mark Matthews19 Sep 2002 13:35 
Mark Matthews19 Sep 2002 13:39 
Subject:Re: executeQuery and INSERT / UPDATE / DELETE
From:Mark Matthews (ma@mysql.com)
Date:09/19/2002 01:39:10 PM
List:com.mysql.lists.java

----- Original Message ----- From: "Andrew Houghton" <aa@volunteermatch.org> To: <ja@lists.mysql.com> Sent: Thursday, September 19, 2002 1:55 PM Subject: executeQuery and INSERT / UPDATE / DELETE

Just started playing with the beta version of Connector/J; I'm getting exceptions in places where executeQuery is being used for DML queries:

Can not issue INSERT/UPDATE/DELETE with executeQuery()

I suppose that makes sense, s'why God invented execute() and executeUpdate() after all, but I can't see that it agrees with the spec. The specification I have for JDBC 3.0 says:

13.1.2 Executing Statement Objects

The method used to execute a Statement object depends on the type of SQL statement being executed. If the Statement object represents an SQL query returning a ResultSet object, the method executeQuery should be used. If the SQL is known to be a DDL statement or a DML statement returning an update count, the method executeUpdate should be used. If the type of the SQL statement is not known, the method execute should be used.

It doesn't say "must", it says "should". Granted that this is one of those gray areas where the English language is being used a little loosely. Could someone in the know tell me if JDBC 3.0 is really meant to be this strict? It's a significant change from JDBC 2.0, where the Java API hinted that executeUpdate() be used with DML queries, but didn't enforce that rule.

They say "should" in the spec, but test "must" in the compliance test. I say code wins.

-Mark