aspose file tools*
The moose likes JDBC and the fly likes Oracle JDBC, auto generated keys Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Oracle JDBC, auto generated keys" Watch "Oracle JDBC, auto generated keys" New topic
Author

Oracle JDBC, auto generated keys

Sean Sullivan
Ranch Hand

Joined: Sep 09, 2001
Posts: 427
When will Oracle's JDBC driver support auto generated keys?

Method: java.sql.Statement.getGeneratedKeys()

Oracle's JDBC FAQ says that auto-generated keys are not supported. (Link: http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm )

The JDBC 3.0 specification states:

{{

Section 13.6

Retrieving Auto Generated Keys

"Many database systems have a mechanism that automatically generates a unique key field when a row is inserted. The method Statement.getGeneratedKeys,

which can be called to retrieve the value of such a key, returns a ResultSet object with a column for each automatically generated key. A flag indicating that any auto generated columns should be returned is passed to the methods execute, executeUpdate or prepareStatement when the statement is executed or prepared. [...]"

}}
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Oracle doesn't have a data type equivalent to Access's autonumber or MySQL's auto increment, so there is nothing for the driver to use. With Oracle you need to use a sequence and select the next PK explicitly before using it. If you wanted to use the getGeneratedKeys() stuff you'd need a way of telling the Statement which sequence you were using for the particular table you are inserting into.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Oracle JDBC, auto generated keys