Original http://eva031007.blog.163.com/blog/static/90782752006521012130/
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page language= "java" import= "java.sql.*"%>
<script language= "JavaScript" >
function Newwin (URL) {
Var
Newwin=window.open (URL, "Newwin", "Toolbar=no,location=no,directories=no,status=no,
Menubar=no,scrollbars=yes,resizable=yes,width=600,height=450 ");
Newwin.focus ();
return false;
}
</script>
<script language= "JavaScript" >
function submit10 ()
{
Self.location.replace ("fenye1.jsp")
}
</script>
<%//Variable Declaration
Java.sql.Connection Sqlcon; Database Connection objects
Java.sql.Statement sqlstmt; SQL Statement Object
Java.sql.ResultSet Sqlrst; Result set Object
Java.lang.String Strcon; Database connection string
Java.lang.String strSQL; SQL statement
int intpagesize; Number of records displayed on one page
int introwcount; Total Records
int intpagecount; Total pages
int intpage; Page number to display
Java.lang.String strpage;
int i;
Set the number of records to display on a page
Intpagesize = 4;
Get the number to display
Strpage = request.getparameter ("page");
if (strpage==null) {//indicates that there is no page this parameter in QueryString, the first page data is now displayed
Intpage = 1;
}
else{//converts a string to an integral type
Intpage = Java.lang.Integer.parseInt (strpage);
if (intpage<1) intpage = 1;
}
Load JDBC Driver
Class.forName ("Sun.jdbc.odbc.JdbcOdbcDriver");
To set the database connection string
Strcon = "Jdbc:odbc:heyang";
Connecting to a database
Sqlcon = Java.sql.DriverManager.getConnection (Strcon, "sa", "");
Create a read-only SQL statement object that can be scrolled
SQLSTMT =
Sqlcon.createstatement (Java.sql.resultset.type_scroll_insensitive,java.sql.result
SET.CONCUR_READ_ONLY);//Prepare SQL statements
strSQL = "Select User_id,user_name from UserInfo order by user_id Desc";
Execute the SQL statement and get the result set
Sqlrst = Sqlstmt.executequery (strSQL);
Get Total Records
Sqlrst.last ()///?? The cursor is on the last line
Introwcount = Sqlrst.getrow ()//Get Current line number
Count Total Pages
Intpagecount = (introwcount+intpagesize-1)/intpagesize;
Adjust the number of pages to be displayed
if (intpage>intpagecount) intpage = Intpagecount;
%>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<title> member Management </title>
<body>
<form method= "POST" action= "fenye1.jsp" >
Page <%=intPage%> Total <%=intPageCount%> page
<%if (intpage<intpagecount) {%><a
href= "fenye1.jsp?page=<%=intpage+1%>" > next page
</a><%}%> <%if (intpage>1) {%><a href= "fenye1.jsp?page=<%=intpage-1%>" >
Previous Page </a><%}%>
Go to page: <input type= "text" name= "page" size= "8" > page
<span><input Class=buttonface type=´submit´value=´go´name=´cndok´></span>
</form>
<table border= "1" cellspacing= "0" cellpadding= "0" >
<tr>
<th>ID</th>
<th> User name </th>
<th width=´8%´> Delete </th>
</tr>
<%
if (intpagecount>0) {
Position the record pointer over the first record of the page you want to display
Sqlrst.absolute ((intPage-1) * intpagesize + 1);
Display data
i = 0;
String User_id,user_name;
while (I<intpagesize &&!sqlrst.isafterlast ()) {
User_id=sqlrst.getstring (1);
User_name=sqlrst.getstring (2);
%>
<tr>
<td><%=user_id%></td>
<td><%=user_name%></td>
<TD width=´8%´align=´center´><a href= "delete.jsp?user_id=<%=user_id%>"
onclick= "return Newwin (THIS.HREF);" > Delete </a></td>
</tr>
<%
Sqlrst.next ();
i++;
}
}
%>
</table>
</body>
<%
Close result set
Sqlrst.close ();
Close an SQL statement object
Sqlstmt.close ();
Close Database
Sqlcon.close ();
%>