Home > Java > javaTutorial > body text

How Does JDBC Manage Batched Statements with MySQL\'s max_allowed_packet Limit?

DDD
Release: 2024-10-27 13:10:30
Original
269 people have browsed it

How Does JDBC Manage Batched Statements with MySQL's max_allowed_packet Limit?

Using RewriteBatchedStatements with MySQL and max_allowed_packet

JDBC's rewriteBatchedStatements configuration optimizes network overhead by packing multiple queries into a single packet. This raises concerns regarding the MySQL server's max_allowed_packet limit.

Reducing Network Overhead with RewriteBatchedStatements

When rewriteBatchedStatements is set to true,JDBC combines queries into a single network packet. For example:

<code class="java">ps.setString(1, "...");
ps.addBatch();
ps.setString(1, "...");
ps.addBatch();
ps.executeBatch();</code>
Copy after login

without rewriteBatchedStatements:

<code class="sql">INSERT INTO jdbc (`name`) VALUES ('Line 1: ...')
INSERT INTO jdbc (`name`) VALUES ('Line 2: ...')</code>
Copy after login

with rewriteBatchedStatements:

<code class="sql">INSERT INTO jdbc (`name`) VALUES ('Line 1: ...'),('Line 2: ...')</code>
Copy after login

JDBC's Awareness of max_allowed_packet

Yes, JDBC is aware of the max_allowed_packet value and adjusts the size of the combined queries accordingly.

Example

By enabling MySQL's general log, you can observe JDBC inspecting max_allowed_packet upon connection. Furthermore, if you set max_allowed_packet to a low value, JDBC will split batch queries into smaller packets if the combined size exceeds the limit.

The above is the detailed content of How Does JDBC Manage Batched Statements with MySQL\'s max_allowed_packet Limit?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!