Bug #2500 Statement.execute() returns true though ResultSet is empty
Submitted: 24 Jan 2004 12:12 Modified: 20 Dec 2004 23:57
Reporter: Jens Bradt Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:4.1.1 (MySQL), 3.0.10 (MySQL Connector/J OS:Windows (Windows ME)
Assigned to: CPU Architecture:Any

[24 Jan 2004 12:12] Jens Bradt
Description:
Statement.execute(Strint) returns true with MySQL Connector/J 3.0.10 and MySQL 4.1.1 though ResultSet is empty. According to Interface java.sql.Statement false should be returned in this case. It worked fine with MySQL Connector/J 3.0.6 and MySQL 4.0.12.

How to repeat:
Statement stmt = con.createStatement();
if (stmt.execute("SELECT int FROM table WHERE 1=2")) {
     ResultSet rs = stmt.getResultSet();
     rs.first();
     rs.getInt(1);
}

throws SQLException: Illegal operation on empty result set
[24 Jan 2004 14:09] Mark Matthews
My API docs state that it returns false when there are no results, however I will need to check with JDBC spec lead, because I interpret this to mean that not even an empty result set was returned (i.e. the result of executing a stored function).

If it is interpreted as 'empty results', this interpretation would be conter to the ability to determine the metadata of even an empty result set, which would not make sense given how the rest of the JDBC API works. This is especially considering the multitude of other places where the determination of empty result sets is demonstrated via using ResultSet.next() in the JDBC API docs.

I see the behavior of the older versions of the driver as a bug, and not JDBC-compliant.
[7 Oct 2008 19:09] pranaykumar kondekar
for select statement you should use statement.executeQuery("Select * from....")
statement.execute is used for insert update delete