0

I have created a Table TEST_DETAIL as

CREATE TABLE TEST_DETAIL(
  TEST_KEY BIGINT DEFAULT CAST(FORMATDATETIME(CURRENT_TIMESTAMP(), 'YYYYMMDDHHMMSSSSS') AS BIGINT) PRIMARY KEY,
  TEST_NO BIGINT DEFAULT TEST_NO_SEQ.NEXTVAL,NAME VARCHAR(40),AGE DECIMAL(5,2),GENDER CHAR(1),ADDRESS VARCHAR(250), MOBILE_NO VARCHAR(20),DATE_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP()
);

I am inserting records into table though jdbc.On insertion I have to retrieve TEST_KEY & TEST_NO.I am able to retrieve TEST_NO as it is a sequence using following logic, as explained here

    int insertedRow=statement.executeUpdate(sSql);          
        if (insertedRow == 0) {
            throw new SQLException("Failed!!");
        }           
        ResultSet rs = statement.getGeneratedKeys();
        if (rs.next()){             
            System.out.println(rs.getInt(1));              
        } 

How to retrieve TEST_KEY which is CURRENT_TIMESTAMP.

Community
  • 1
  • 1
2FaceMan
  • 443
  • 2
  • 18
  • 34

1 Answers1

0

Try using an explicit definition of the auto generated keys you want to get back:

int insertedRow = statement.executeUpdate(sSQL, new String[]{"TEST_KEY", "TEST_NO"});

Here are Javadocs for the method:

https://docs.oracle.com/javase/7/docs/api/java/sql/Statement.html#executeUpdate%28java.lang.String,%20java.lang.String[]%29

Slava Imeshev
  • 1,360
  • 10
  • 14