Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting prrimary key into other table as foreign key.

 
Mohan Karthick
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
All right .... Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic