Mysql fetch size Problems

Source: Internet
Author: User

Mysql fetch size problems by default, MySQL's JDBC driver will read all rows at once, which is generally the best, this reduces the communication overhead of the Client-Server. However, there is also a problem. When the database query results are very large, especially when not all can be put into the memory, it will produce performance problems. Originally, the JDBC api has the fetchSize setting method on Connection, Statement, and ResultSet, but the JDBC driver of MySQL does not support it, no matter how you set fetchSize, all ResultSet reads data from Serv er at a time. There are also many such problems on the official MySQL Forum. The solution is summarized as follows: 1. mySQL version 5.0 or later, MySQL JDBC driver updated to the latest version (at least 5.0 or later) 2. statement must be TYPE_FORWARD_ONLY, And the concurrency level is CONCUR_READ_ONLY (that is, the default parameter for creating Statem ent) 3. select one of the following two statements: 1 ). statement. setFetchSize (Integer. MIN_VALUE); 2 ). (com. mysql. jdbc. statement) stat ). enableStreamingResults (); this will read data from the Server row by row, so the communication overhead is high, but the memory problem can be solved. The official statement is that fetchSize is not supported by MySQL, but not by MySQL itself. The commercial database Oracle or DB2 both support fetchSize, so we can see that the two have different considerations.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.