#{茶男與藍牌}
!Statement.GeneratedKeysNotRequested!
Happen on version 5.1.7, so switch back to 5.1.6 is the solution…
From http://bugs.mysql.com/bug.php?id=41448
| Bug #41448 | java.sql.SQLException: !Statement.GeneratedKeysNotRequested! | ||
|---|---|---|---|
| Submitted: | 13 Dec 2008 18:22 | Modified: | 28 May 20:29 |
| Reporter: | Rico H. | ||
| Status: | Documenting | ||
| Category: | Connector/J | Severity: | S1 (Critical) |
| Version: | 5.1.7 | OS: | Linux |
| Assigned to: | Target Version: | ||
Tagged with: MySQL
-
Articles
- February 2012
- December 2011
- November 2011
- October 2011
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- January 2011
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
-
Meta




Description: Hello, Consider the following code: PreparedStatement ps = connection.prepareStatement("INSERT INTO table values(?,?)"); ps.setInt(1,value1); ps.setInt(2,value2); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); // This throws a java.sql.SQLException: !Statement.GeneratedKeysNotRequested! Even when creating the PreparedStament in this other way the same exception is thrown: PreparedStatement ps = connection.prepareStatement("INSERT INTO table values(?,?)",PreparedStatement.RETURN_GENERATED_KEYS); ps.setInt(1,value1); ps.setInt(2,value2); ps.executeUpdate(); ResultSet rs = ps.getGeneratedKeys(); // This ALSO throws a java.sql.SQLException: !Statement.GeneratedKeysNotRequested! According to some posts I read on the Internet, this might be related to Bug #34185, as it seems was pushed into the current 5.1.7 version and the problem didn't happen before. I guess the problem just occurs when using PreparedStaments, as with Statements you can provide the RETURN_GENERATED_KEYS flag when executing the query. However, flags for PreparedStaments can only be provided when "Preparing the Statement". So the following code works well: Statement stmt = connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_ READ_ONLY); stmt.executeUpdate("INSERT INTO table values(1,2)",Statement.RETURN_GENERATED_KEYS); ResultSet rs = stmt.getGeneratedKeys(); //This works This is breaking lots of apps, and should be fixed as soon as possible. Thank you very much!! How to repeat: See description!