Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Oracle JDBC, auto generated keys

 
Sean Sullivan
Ranch Hand
Posts: 427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic