Since JDBC 3.0 it has been posible to retrieve the keys that are generated on a database when an SQL insert is executed, using the getGeneratedKeys() method on the statement object. For some reason the latest Oracle JDBC driver that claims that implement this method, has a non standard behaviour (that is not strange on Oracle):
It does not returns the generated keys values, it only returns a value for a propietary object implementation named ROWID. One of the solutions was to use that ROWID in a query to retrieve the other generated columns:
SELECT KEY_1, KEY_2, KEY_3 FROM MYTABLE WHERE ROWID = ?
where KEY_1, KEY_2, KEY_3 are the generated columns I want to know its value. The other solution is not to use the int parameter (with the value Statement.RETURN_GENERATED_KEYS) in the PreparedStatement, instead use the one that needs the generated column names or indexes.
Another reason why I prefer IBM DB2 and PostgreSQL over Oracle.










Comments (0) |
Trackbacks (0)