In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the solution of excessive memory overflow of sql query data, which is very detailed and has a certain reference value. Interested friends must read it!
Normally, this does not happen, but there is no guarantee that it happens occasionally, and the solution is as follows:
Use paging query statements.
Because the paging query only queries a small amount of data at a time, it does not take up too much memory, and when the amount of data is large, the paging query will save some time.
String sql = "SELECT uid,uname FROM t_user LIMIT?,?"; PreparedStatement ps = con.prepareStatement (sql); int pageSize = 10000; int pageId = 0; do {pst.setInt (1, pageId * pageSize); pst.setInt (2, pageSize); ResultSet rs = pst.executeQuery (); boolean isEmpty = true While (rs.next ()) {isEmpty = false; id = rs.getInt (1); name = rs.getString (2);} if (isEmpty) {break;} pageId++;} while (true); con.close () } catch (SQLException e) {e.printStackTrace ();}
Add url parameter configuration
Add two parameters to the URL of jdbc to OK, and successfully solve the problem of memory overflow.
"jdbc:mysql://localhost:3306/db3?useCursorFetch=true&defaultFetchSize=100"
To explain Fetch, when we execute a SQL query, we need to open a cursor on both the client side and the server side, and request a piece of memory space as a buffer to store the query data. In this memory area, the number of pieces of data stored is determined by fetchsize, and each network packet sends fetchsize records to the client)
These are all the contents of this article entitled "the solution to excessive memory overflow of sql query data". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.