aspose file tools*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "preparedstatement addBatch" Watch "preparedstatement addBatch" New topic
Author

preparedstatement addBatch

Dev Anand
Ranch Hand

Joined: Aug 30, 2009
Posts: 41
Hi,
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

Regards
Dev Anand
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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.

Regards
Dev Anand
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: preparedstatement addBatch