Connector J Error: "java.sql.SQLException: Generated keys not requested"

(Doc ID 1382309.1)

Last updated on MARCH 14, 2017

Applies to:

MySQL Connectors - Version 5.1 and later
Information in this document applies to any platform.

Symptoms

Sometimes upgrading Connector/J to a new version (spotted with 5.1.18) can cause the following exception (especially if the client program code is old):

Caused by: java.sql.SQLException: Generated keys not requested. You need to specify Statement.RETURN_GENERATED_KEYS to Statement.executeUpdate() or Connection.prepareStatement().

Changes

From Connector/J 5.1.7 onward (Bug #11747826), an exception is now thrown when getGeneratedKeys() is called on a statement that had not been created with RETURN_GENERATED_KEYS.

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms