Arpit
Arpit

Reputation: 601

Limit MySQL Batch size in jConnector

I have a JDBC application, to convert insert statements into batch I used rewriteBatchedStatements=true in MySQL connection string but I also need to limit my batch size to 100. How can I do it?

Upvotes: 2

Views: 1138

Answers (2)

Karol Dowbecki
Karol Dowbecki

Reputation: 44942

On the server side max_allowed_packet will limit the count of INSERT clobbed together by rewriteBatchedStatements. As per 5.1.8 Server System Variables:

The maximum size of one packet or any generated/intermediate string, or any parameter sent by the mysql_stmt_send_long_data() C API function. The default is 64MB.

If you need more fine grained control you must use JDBC e.g. by calling executeBatch() after each N rows.

Upvotes: 3

Alexander Katanov
Alexander Katanov

Reputation: 46

You can make commit of current transaction (or flush session) every 100 rows you trying to insert.

Upvotes: 0

Related Questions