Bug #1929 describe how to use RETURN_GENERATED_KEYS with prepared statements
Submitted: 24 Nov 2003 0:08 Modified: 24 Nov 2003 6:05
Reporter: Ralf Hauser Email Updates:
Status: Not a Bug Impact on me:
Category:Connector / J Severity:S4 (Feature request)
Version:3.1.nightly OS:Linux (RH 9)
Assigned to: Mark Matthews CPU Architecture:Any

[24 Nov 2003 0:08] Ralf Hauser

The description in http://www.mysql.com/articles/autoincrement-with-connectorj.html is excellent, but I tried to do this with my prepared statement and it appears that in prepared statements, the stmt.executeUpdate() never has any arguments.
First, I thought this may be only a documentation RFE, but perhaps, the PreparedStatement.java lacks this method signature, i.e.
   .executeUpdate(int autoGeneratedKeys)


How to repeat:

Suggested fix:
[24 Nov 2003 6:05] Mark Matthews
You need to use the correct method on Connection.prepareStatement(). The following methods allow you to specify which (if any) keys to return:

Connection.prepareStatement(String, int), see:

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#prepareStatement(java.lan..., int)

Connection.prepareStatement(String, int[]), see:

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#prepareStatement(java.lan..., int[])

Connection.prepareStatement(String, String[]), see:

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#prepareStatement(java.lan..., java.lang.String[])
[24 Nov 2003 10:19] Ralf Hauser
Thanks, I guess this solves it - maybe a one-line amendment to your article that for prepared statements, the "int autoGeneratedKeys" is no longer in executeUpdate(), but in prepareStatement(...) may avoid future, similar questions.