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

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -