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:
[13 Dec 2008 18:22] Rico H.
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!