Pagination | data | database | When you access a database with JDBC and read out a ResultSet data recordset, if the number of records is too large, it consumes a lot of memory from the client (the machine that is running the Java program) (if the client is a proxy extension to the business unit of a large enterprise), It is possible that the Java program takes up full memory and then complains, and it can cause the client to overload and run at an extremely slow pace (I have done a test in the Sybase database.) When you select a large data record, the SQL statement takes 4 minutes to complete and nearly 10 minutes when the Java client is fully displayed. Solution:
Gives the user an option to select a paging display, which is displayed if the user does not want the page to be displayed, otherwise the paging is displayed.
1. Define a single page global constant, that is, the number of data bars that are displayed per sheet.
Private final static int SKIP = 100;
2. Defines a global variable that determines the number of page bars, that is, the number of current display data bars for that display page.
private static int cur = 0;
3. Define a resultset global variable for multiple use
5. Get the query result set data (usually in the response event function of the query button)
... nextbutton.setenable (true); cur = 0; while (cur < SKIP && Rs.next ()) {cur + +; ..... (Get the records in RS, in the variables in the Java program)}
6. Display the result set data for the next page (typically in the response event function of the next page button)
if (rs.getrow () = = 0) {nextbutton.setenable (false); CloseConnection (); --rs's cursor has arrived. Finally, the result set is displayed and the connection is closed cur = 0; if (Rs!= null && rs.getrow () > 0) {.... Clears the content displayed on the previous page while (cur < SKIP && Rs.next ()) {cur + +; ..... (Gets the record in the result set, stored in a variable in the Java program)} }
Flaw: This method is generated according to the ResultSet class prior to version 2.0 of JDBC (specific to the provider of the JDBC driver) because ResultSet cannot rollback the result set that has already been displayed, so this method can only be defined by the ResultSet class, from left to right, Browse data results from the past. Unable to dynamically display result set data before or after any specified.
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.