In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
MYSQL JDBC fast query response method and how to quickly return the implementation of the mechanism, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.
Has been very difficult, Oracle fast return mechanism, although there are many result sets, but it can quickly display the first result, although it can be done through the client of MYSQl, but not through JDBC.
It took more than an hour today, and finally solved this problem. I hope to have a reference for the majority of Java friends when dealing with it.
The reason is:
By adding the-Q parameter to the command line client, you can respond to a query very quickly.
For example, for select * from T1 with a result set of tens of millions, it takes 20 seconds to complete the result set, and it takes less than 1 second to display the first row with the-Q parameter.
However, the above effect can not be achieved by querying through jdbc, no matter how to adjust the URL parameters.
Process:
Check the explanation of the-Q parameter, as follows:
If you have problems due to insufficient memory for large result sets
Use the-- quick option. This forces to retrieve results
From the server a row at a time rather than retrieving the entire result set
And buffering it in memory before displaying it. This is done by returning
The result set using the mysql_use_result () C API function in the client/server
Library rather than mysql_store_result ().
It can be seen that fast response is achieved.
Take a look at the mysql_use_result () function, which is the API of C, which you can use if you develop through C.
What about JAVA?
Look for the relevant functions in the JDBC specification, without any gain. SetFetchSize () looks effective, but in the actual test, there is no performance improvement.
Search for JDBC mysql_use_result and get a windfall.
The following content is found in the JDBC,com.mysql.jdbc.Statement API of MYSQL:
Abstract public void disableStreamingResults () throws SQLException
Resets this statements fetch size and result set type to the values they
Had before enableStreamingResults () was called.
Abstract public void enableStreamingResults () throws SQLException
Workaround for containers that 'check' for sane values of Statement.setFetchSize ()
So that applications can use the Java variant of libmysql's mysql_use_result () behavior.
It turns out that MySQL provides a quick response implementation of its own. Adjust the test code
Stmt = (com.mysql.jdbc.Statement) con.createStatement ()
Stmt.setFetchSize (1)
/ /
/ / turn on the stream return mechanism
Stmt.enableStreamingResults ()
The effect I was looking forward to appeared. The first line of data is quickly realised in less than a second.
MySQL provides unique functions in its own JDBC driver to achieve fast response to queries.
It is especially effective when the result set is very large or takes a long time, and the user really wants to see the first result as soon as possible.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.