• 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

Inserting prrimary key into other table as foreign key.

 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say I have one table EMP and other DEPT both are having auto generated primary key , and DEPT key keep EMP's promary key as a foreign key.

Now what is the best JDBC flow, if some onw wnat to insert emp info and dept infor together.
so flow is first it will insert EMP details and new row generate a primary key, I will pick up this primary by another JDBC call, and again inset it into DPET table with dept details, and another JDBC call. That means there are total three Databse call!!
Please advice any toher efficient flow.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mohan,
Three database calls isn't necessarily a problem. First write the code the clearest way and then time to see if there are any performance issues.

Depending on your database, you may only need two calls. Some databases (like Oracle) will return the generated key for you.
 
Mohan Karthick
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right .... Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic