jQuery in Action, 2nd edition*
The moose likes JDBC and the fly likes preparedstatement addBatch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "preparedstatement addBatch" Watch "preparedstatement addBatch" New topic

preparedstatement addBatch

Dev Anand
Ranch Hand

Joined: Aug 30, 2009
Posts: 41
Is it an efficient approach to go for batch execution if we have 5 or 6 records to insert or update using preparedstatement?
Can anyone help me for better approach?
Thanks in advance

Dev Anand
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3606

Generally speaking, this is the most efficient way to do it, though various databases might differ a bit.

Just for an example - in Oracle, with JDBC driver older than 11g, this does not yield the most efficient mechanism; you'd need to use Oracle specific methods to achieve the best possible performance. With 11g JDBC driver, the standard JDBC batching achieves the topmost performance without need for any Oracle specific processing.

On the other way, you're not going to get significant savings on five or six executions. You should use the standard batching - no doubts about it, but that's probably all. On the other hand, if you'd be executing the command hundreds or thousands times, it might be a good idea to check with your specific JDBC driver/database documentation to find out whether a more efficient alternative exists. Or ask here again with the full database and JDBC driver specification; someone might be able to advice you in your particular situation.
Dev Anand
Ranch Hand

Joined: Aug 30, 2009
Posts: 41
Thanks Martin for your information.

Dev Anand
I agree. Here's the link: http://aspose.com/file-tools
subject: preparedstatement addBatch
Similar Threads
Get only date in a select statement
store pdf on file to another file
Update query
How to insert variable value in select?
Executing PreparedStatement only once and Executing Statement only once