Simplely sorted out the paging, I hope to help beginners

zhaozj2021-02-16  54

Preparation: Under Oracle, create a table: CREATE TABLE MyTable (ID INT, Name Varchar (32)) /

Insert some values ​​in Table MyTable.

The TestPage.JSP page program is as follows:

<% @ page import = "java.util. *"%> <% @ Page import = "java.lang. *"%> <% @ Page import = " Java.io. * "%> <% @ page import =" java.sql. * "%> <% @ page import =" java.net. * "%> <% @ Page ContentType =" text / html; charSet = GBK "%>

<% String sconn = "JDBC: Oracle: Thin: @HOST: 1521: ORCL"; Class.Forname ("Oracle.jdbc.driver.Oracledriver); Connection Conn = DriverManager.getConnection (Sconn," User "," PASSWORD "); Statement stmt = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); // Statement stmtcount = conn.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

ResultSet RS = Stmt.executeQuery ("Select * from myTable"); // string sqlcount = "select count (*) from mytable"; // resultset = stmtcount.executeQuery (Sqlcount);

INT Pagesize = 5; // 5 per page INT ROWCOUNT = 0; // Total number of records

Rs.last (); rowcount = rs.getrow ();

INT pageCount; // Total page number int currpage = 0; // Current page String strpage; strPage = Request.getParameter ("Page");

if (strPage == null) {currPage = 1;} else {currPage = Integer.parseInt (strPage); if (currPage <1) currPage = 1;} pageCount = (rowCount pageSize-1) / pageSize; if (currPage > PageCount);

INT thepage = (currpage-1) * Pagesize; int N = 0;%>

Current: <% = currpage%> page

Home <% IF (Currpage> 1) {%> Next <%}%> Last"



A total of <% = rowcount%> Page: <% = currpage%> / <% = pagecount%> page <% = pagesize%> bar / page

<% if (currpage> 0) {r.absolute (thepage 1); while (n < TD> "); out.println (rs.getint (1) "
"); Out.println (rs.getstring (2) " "); rs.next (); n;}

}%>

<% Rs.close (); //rscount.close (); stmt.close (); //stmtcount.close (); conn.close ();%>

// Even on Oracle8.1.6 test, the result can be displayed, but the Name field value is like a 16-way byte string. But there is no problem after oracle8.1.7. It may be different from JDBC.

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.047, SQL: 9