How to implement pagination display in JSP?
Page Display is a problem that often needs to be encountered in Web database applications. When the user's database query results are far exceeded the display capabilities of the computer screen, what should we reasonably present to users? The answer is that the database paging display is perfect to solve the above problems. Below is a general instance of a database paging operation, which has a good reference to the paging function on any database platform.
<% @ Page contenttype = "text / html; charset = 8859_1"%> <% // variable declaration java.sql.connection sqlcon; // database connection object java.sql.Statement SQLSTMT; // SQL statement object java.sql .Resultset Sqlrst; // Results
Java.lang.String strcon; // Database connection string java.lang.string strsql; // sql statement
INT INTPAGESIZE; // A page display record number int intert ket; // Remove total INT INT INT INT INT INT INT INT INT INTPAGE; // Terfer to display page Java.lang.String StrPage;
INT I;
/ / Set the record number of records INTPAGESIZE = 2;
// Nourish the page number to be displayed StrPage = Request.getParameter ("page"); if (strpage == null) {// indicates that there is no page of Page in querystring, showing the first page data INTPAGE = 1;} else {/ / Convert a string to integer = java.lang.integer.Parseint (STRPAGE); if (INTPAGE <1) INTPAGE = 1;}
// Load JDBC driver java.sql.driverManager.RegisterDriver (new oracle.jdbc.driver.Orcledriver ());
// Set database connection string strCon = "JDBC: Oracle: Thin: @linux: 1521: Ora4cWeb";
// Connect the database SQLCON = java.sql.driverManager.getConnection (StrCon, "Hzq", "Hzq");
// Create a read-only SQL statement object that can scroll sqlstmt = sqlcon.createstatement (java.sql.resultset.Type_scroll_insensitive, java.sql.resultset.concur_read_only);
// Prepare SQL statement strsql = "select name, age from test";
// Execute the SQL statement and get the result set sqlrst = SQLSTMT.ExecuteQuery (strsql);
// Get the total number of records sqlrst.last (); Introwcount = Sqlrst.Getrow ();
/ / Mode total page INTPAGECOUNT = (Introwcount INTPAGESIZE-1) / INTPAGESIZE;
// Adjust the page number if (INTPAGE> INTPAGECUNT) INTPAGE = INTPAGECUNT;%>
<% IF (INTPAGECUNT> 0) {// Position the record pointer to the first record of the page to be displayed on SQLRST.ABSOLUTE ((INTPAGE-1) * INTPAGESIZE 1);
// Display data i = 0; while (i TABLE> No. <% = INTPAGE%> page A total of <% = INTPAGECOUNT%> page <% IF (INTPAGE Body> html> <% // Close the result set sqlrst.close (); // Turn off the SQL statement object SQLSTMT.Close (); // Turn off the database sqlcon.close ();%> comprehensive analysis JDBC <% = sqlrst.getstring (1)%> td> <% = sqlrst.getstring (2)%> td> tr> <% sqlrst.next (); i ;}}%>