java - Primary key from inserted row jdbc? -
is there cross database platform way primary key of record have inserted?
i noted this answer says can calling select last_insert_id()
, think can call select @@identity 'identity';
there common way accross databases in jdbc?
if not how suggest implement piece of code access of sql server, mysql , oracle?
copied code:
pinsertoid = connection.preparestatement(insert_oid_sql, statement.return_generated_keys);
where pinsertoid prepared statement.
you can obtain key:
// fill in prepared statement , pinsertoid.executeupdate(); resultset rs = pinsertoid.getgeneratedkeys(); if (rs.next()) { int newid = rs.getint(1); oid.setid(newid); }
hope gives starting point.
Comments
Post a Comment