Bug #2957 getStatement returns null for ResultSet returned by getGeneratedKeys
Submitted: 25 Feb 2004 7:47 Modified: 5 Mar 2004 14:24
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:3.0.10 OS:
Assigned to: Mark Matthews CPU Architecture:Any

[25 Feb 2004 7:47] [ name withheld ]
Description:
The JDBC specification isn't clear on this, but I'd have expected the fragment in the 'how to repeat' field below to work. At the moment the result set returned by the getGeneratedKeys call doesn't know what it's owning statement is, so the final stmt.close() will throw a NullPointerException.

How to repeat:
stmt = conn.prepareStatement("insert into ...", Statement.RETURN_GENERATED_KEYS);
...
stmt.execute();
rs = stmt.getGeneratedKeys();
...
stmt = rs.getStatement();
stmt.close();

Suggested fix:
com/mysql/jdbc/Statement.java:getGeneratedKeys perhaps ought to call 'setStatement' after it creates the ResultSet, if that's the correct interpretation of the JDBC 3.0 spec.
[5 Mar 2004 14:24] Mark Matthews
This will end up in 3.0.12. You can check out a nightly snapshot from http://downloads.mysql.com/snapshots.php if you need to test it earlier.