Bug #692 mysql executequery data manipulation error
Submitted: 20 Jun 2003 6:49 Modified: 20 Jun 2003 7:03
Reporter: [ name withheld ] Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.0.8 stable OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[20 Jun 2003 6:49] [ name withheld ]
Description:
Can not issue data manipulation statements with executeQuery() 
when running MySQL from Tomcat.  The query works ok from the command line.

java.sql.SQLException: Can not issue data manipulation statements with executeQuery()
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:1093)
        at pubadmin.LoadFactSheet.service(LoadFactSheet.java:192)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:469)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.connector.warp.WarpRequestHandler.handle(Unknown Source)
        at org.apache.catalina.connector.warp.WarpConnection.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:536)

How to repeat:

sqlQuery = "UPDATE documents SET web_exp = NOW() WHERE fund_id='" + fund_id + "' AND doctype='" + doctype + "' AND web_ver ='" + web_ver + "' AND (web_exp IS NULL OR TO_DAYS(web_exp) > TO_DAYS(NOW()))";
rs = stmt.executeQuery(sqlQuery);
[20 Jun 2003 7:03] Mark Matthews
The JDBC spec states that you must either use Statement.executeUpdate() or Statement.execute() for queries that manipulate data (such as your 'UPDATE documents SET web_exp....' query).

Older versions of the JDBC driver were more lax on this. However, it is important to be JDBC-compliant, so the later versions of the driver enforce this requirement.