Page Display Records read from the database

xiaoxiao2021-03-06  19

Access to one by JDBC

Database, and read a RESULTSET data record set, if the number of records is too large, a large amount of memory that will occupy the client (running the Java program) (if the client is a big business agent agent agent, It is possible that the Java program will take full memory, then report the error), and will cause the client load too heavy, the running speed is extremely slow (in the Sybase database, I have done a test. Select a big data record, SQL statement It takes 4 minutes to run, and it takes near 10 minutes to the Java client.

solution:

Provide a user with an option to select pagination display, if the user does not want to make a page display, it is fully displayed, otherwise pagination display.

1. Define a single-page number global constant, that is, the number of data from each page.

PRIVATE FINAL static int SKIP = 100;

2. Define a global variable that determines the number of pagins, that is, the current display of the currently displayed data.

Private static int Cur = 0;

3. Define a RESULTSET global variable so that you can use multiple times.

Private static java.sql.result rs = null;

4. Open a database connection [/ pre]

Class.Forname (Sqldriver); java.sql.connection conn = drivermanager.getConnection (url, (string) username (String) passwd) statement stmt = conn.createstatement (); string searchsql = "..." Rs = stmt.executeQuery (SearchSQL);

5. Get the query result set data (generally in the response event function in the query button)

... nextButton.seTenable (TRUE); cur = 0; while (Cur

6. Display the result set data of the next page (usually in the response event function of the next page button)

IF (rGetrow () == 0) {nextButton.seTenable (false); CloseConnection (); --RS CURSOR has arrived, the result set is shown, close this connection} CUR = 0; IF (RS ! = NULL && RS.GETROW ()> 0) {.... Clear the content displayed on the page (Cur

Defect: This method is generated according to the RESULTSET class before version 2.0 JDBC (relevant to the JDBC driver), because ResultSet can't roll back the result set that has already been displayed, so this method can only follow the Resultset class, from Left to the right, from the procedure of the browsing data. Unable to dynamically display the specified result set data.

转载请注明原文地址:https://www.9cbs.com/read-39768.html

New Post(0)