This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert in JDBC

 
Anselm Paulinus
Ranch Hand
Posts: 390
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An interview question I had recently, given about 100,000 records to insert in a persistent storage using JDBC; What is the most efficient way of doing this. Would I have to call commit 100,000 times to do this?
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, using a procedure that is compiled by your SQL server is one step. Using the JDBC batch method is a good step, too. As for the commit, that would depend on whether it is called for or not. If the inserts are all truly atomic, then yes--each commit needs to be called. (See the batch method for specifics though). If they all need to be completely inserted, or none, then the commit would only need to be called once.
 
Anselm Paulinus
Ranch Hand
Posts: 390
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nathaniel
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic