This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Insert in JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert in JDBC" Watch "Insert in JDBC" New topic

Insert in JDBC

Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
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

Joined: May 29, 2003
Posts: 1258
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

Joined: Sep 05, 2003
Posts: 389
Thanks Nathaniel
I agree. Here's the link:
subject: Insert in JDBC
Similar Threads
Limiting the Fetch Size
Add batch (batch insertion into the database)
Using JDBC versus Stored Procedures
singleton class