简体   繁体   中英

Multiple statements in one SQL-query, or use Batch?

I'm sending a long list of updates to a database from a Java-program. I'm wondering if there's a speed difference between

  • Putting all the updates in one query and execute that
  • Making a preparedStatement, adding every update to the batch and executing the batch

Using PreparedStatement and batching would be the preferred approach. It reduces the network traffic between the client and the database server.

Yes it does! It will reduce the traffic between application and server.

I know you mentioned java but just as an example, this is a hint from a C# book Im reading :

NOTE FREE PERFORMANCE UPGRADE!
Setting UpdateBatchSize to 0 is a quick way to boost the update performance of the
DbDataAdapter object. (Setting the value to 0 instructs the DbDataAdapter object to create the largest possible batch size for changes)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM