?? 7-09.jsp
字號:
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<HTML><BODY>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
String strSQL = "";
int PageSize = 5;
int Page = 1;
int totalPage = 1;
int totalrecord = 0;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce){
out.println(ce.getMessage());
}
try{
conn=DriverManager.getConnection("jdbc:odbc:grade");
stmt=conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
//算出總行數
strSQL = "SELECT count(*) as recordcount FROM grade";
rs = stmt.executeQuery(strSQL);
if (rs.next()) totalrecord = rs.getInt("recordcount");
//輸出記錄
strSQL = "SELECT * FROM grade";
rs = stmt.executeQuery(strSQL);
if(totalrecord % PageSize ==0)// 如果是當前頁碼的整數倍
totalPage = totalrecord / PageSize;
else // 如果最后還空余一頁
totalPage = (int) Math.floor( totalrecord / PageSize ) + 1;
if(totalPage == 0) totalPage = 1;
if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
Page = 1;
else
try {
Page = Integer.parseInt(request.getParameter("Page"));
}
catch(java.lang.NumberFormatException e){
// 捕獲用戶從瀏覽器地址攔直接輸入Page=sdfsdfsdf所造成的異常
Page = 1;
}
if(Page < 1) Page = 1;
if(Page > totalPage) Page = totalPage;
rs.absolute((Page-1) * PageSize + 1);
out.print("<TABLE BORDER='1'>");
for(int iPage=1; iPage<=PageSize; iPage++)
{
out.print("<TR><TD>"+rs.getString("學號")+"</TD>");
out.print("<TD>"+rs.getString("姓名")+"</TD>");
out.print("<TD>"+rs.getString("語文")+"</TD>");
out.print("<TD>"+rs.getString("數學")+"</TD>");
out.print("<TD>"+rs.getString("英語")+"</TD></TR>");
if(!rs.next()) break;
}
out.print("</TABLE>");
}
catch(SQLException e){
System.out.println(e.getMessage());
}
finally{
stmt.close();
conn.close();
}
%>
<FORM Action="7-09.jsp" Method="GET">
<%
if(Page != 1) {
out.print(" <A HREF=7-09.jsp?Page=1>第一頁</A>");
out.print(" <A HREF=7-09.jsp?Page=" + (Page-1) + ">上一頁</A>");
}
if(Page != totalPage) {
out.print(" <A HREF=7-09.jsp?Page=" + (Page+1) + ">下一頁</A>");
out.print(" <A HREF=7-09.jsp?Page=" + totalPage + ">最后一頁</A>");
}
%>
<BR>輸入頁數:<input TYPE="TEXT" Name="Page" SIZE="3">
頁數:<font COLOR="Red"><%=Page%>/<%=totalPage%></font>
</FORM>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -