Not able to retrieve primary key generated during insertion of row.
Hi,
I'm trying to get the primary key generated using ResultSet.getGeneratedKeys() method on Oracle 11g using JDBC code. I tried ojdbc14.jar and oddbc6.jars but still getting exception as given below:
java.sql.SQLException: Invalid column type: getLong not implemented for class oracle.jdbc.driver.T4CRowidAccessor
at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException (DatabaseError.java:146)
at oracle.jdbc.driver.Accessor.unimpl(Accessor.java:3 58)
at oracle.jdbc.driver.Accessor.getLong(Accessor.java: 496)
at oracle.jdbc.driver.OracleReturnResultSet.getLong(O racleReturnResultSet.java:290)
The code snippet is as follows:
connection = DriverManager.getConnection(DB_URL,USER,PASS);
....
....
ps.executeUpdate();
ResultSet rs = ps.getGeneratedKeys();
if (rs.next()) {
long newId = rs.getLong(1);
Please let me know if I'm missing out something or give any pointers for the issue.
Re: Not able to retrieve primary key generated during insertion of row.
a) Is the data type you are accessing a long type? It seems, based upon the exception, the driver you are using does not support the getLong method...have you tried others? b) Do you pass the Statement.RETURN_GENERATED_KEYS flag when creating the Statement (or, I presume, the PreparedStatement)?