<%
//變數聲明
java.sql.Connection sqlCon; //資料庫連接對象
java.sql.Statement sqlStmt; //SQL語句對象
java.sql.ResultSet sqlRst; //結果集對象
java.lang.String strCon; //資料庫連接字串
java.lang.String strSQL; //SQL語句
int intPageSize; //一頁顯示的記錄數
int intRowCount; //記錄總數
int intPageCount; //總頁數
int intPage; //待顯示頁碼
int layer;
int idlayer;
idlayer=1;
java.lang.String outtext;
outtext="";
java.lang.String strPage;
int j;
int i;
//設定一頁顯示的記錄數
intPageSize = 10;
//取得待顯示頁碼
strPage = request.getParameter("page");
if(strPage==null){//表明在QueryString中沒有page這一個參數,此時顯示第一頁資料
intPage = 1;
}
else{//將字串轉換成整型
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
//裝載JDBC驅動程式
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
//串連資料庫
sqlCon = java.sql.DriverManager.getConnection("jdbc:mysql://218.22.156.3/kjeny_db","kjeny","cdgame");
//建立語句對象
sqlStmt = sqlCon.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
//執行SQL語句並擷取結果集
sqlRst = sqlStmt.executeQuery("SELECT * FROM dxswlxh");
//擷取記錄總數
sqlRst.last();
intRowCount = sqlRst.getRow();
//記算總頁數
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
//調整待顯示的頁碼
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<base target="contents">
<LINK rel="stylesheet" href="css.css">
<script language="JavaScript">
function byteLen(str) {
var iByteLen = 0;
if (str == null || str == "") {
iByteLen = 0;
} else {
for (var i = 0; i < str.length; i++) {
if(str.charCodeAt(i) < 0x80) {
iByteLen++;
} else {
iByteLen += 2;
}
}
}
return iByteLen;
}
</script>
</head>
<body topmargin="0" leftmargin="0" bgcolor=ccffcc>
<table width="100%"><tr><td bgcolor="ff66cc">
>> 分頁
<form method=post action="pink.jsp?page=1" target=ttop>
<input type=submit value="首 頁">
</form>
<%if(intPage>1){
%>
<form method=post action="pink.jsp?page=<%=intPage-1%>" target=ttop>
<input type=submit value=上一頁>
</form>
<%}%>
<%if(intPage<intPageCount)
{%>
<form method=post action="pink.jsp?page=<%=intPage+1%>" target=ttop>
<input type=submit value=下一頁>
</form>
<%}%>
<form method=post action="pink.jsp?page=<%=intPageCount%>" target=ttop>
<input type=submit value="尾 頁">
</form>
頁次:<%=intPage%>/<%=intPageCount%>頁 <%=intPageSize%>條/頁
</td></tr></table>
<table>
<td width="%100"><ul><%
if(intPageCount>0){
sqlRst.absolute((intPage-1) * intPageSize + 1);
i = 0;
while(i<intPageSize && !sqlRst.isAfterLast()){
String names = sqlRst.getString(3);
String use_xi = sqlRst.getString(4);
%>
<li><%=names%> - 【<%=use_xi%>】
<%
sqlRst.next();
i++;
}
}
%>
</ul></td></table>
</body>
</html>
<%
//關閉結果集
sqlRst.close();
//關閉SQL語句對象
sqlStmt.close();
//關閉資料庫
sqlCon.close();
%>