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:
Comments
Post a Comment