• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

2 inserts - urgent

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to insert two records into a Oracle DB, which are linked via object id's which are generated from a sequence.
So, the code would be:
Create Record1
Set Record1.Id = some sequence
Create Record2
Record2.Link = Record1.Id
But, once I have created record1 how do I know which record was created, or with which sequence?
Please help.
snisar@caluk.com
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you just run a SELECT statement to get the sequence number and store it in a variable for later use?
long sequenceNum = 0;
ResultSet rs = Statement.executeQuery("select sequence_name.nextval from dual");
if (rs.next() ) sequenceNum = rs.getLong(1);
Brian
 
reply
    Bookmark Topic Watch Topic
  • New Topic