jdbc - Retrieve non-sequence value on insert using Java -


i have created table test_detail

create table test_detail(   test_key bigint default cast(formatdatetime(current_timestamp(), 'yyyymmddhhmmsssss') 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 inserting records table though jdbc.on insertion have retrieve test_key & test_no.i able retrieve test_no sequence using following logic, 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 retrieve test_key current_timestamp.

try using explicit definition of auto generated keys want back:

int insertedrow = statement.executeupdate(ssql, new string[]{"test_key", "test_no"}); 

here javadocs method:

https://docs.oracle.com/javase/7/docs/api/java/sql/statement.html#executeupdate%28java.lang.string,%20java.lang.string[]%29


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -