Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2011
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default 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)?

Similar Threads

  1. JPA Primary Key from two foreign key
    By peterbo in forum New To Java
    Replies: 6
    Last Post: 06-29-2014, 10:30 AM
  2. JPA Composite Primary Key
    By The_S in forum Advanced Java
    Replies: 2
    Last Post: 02-06-2009, 06:30 AM
  3. How to generate primary key in EJB
    By naresh_m in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 07-17-2008, 09:41 AM
  4. Replies: 0
    Last Post: 05-14-2008, 09:46 AM
  5. how to determine the primary key
    By osval in forum JDBC
    Replies: 1
    Last Post: 08-07-2007, 02:31 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •