js|分页
<% page contentType="text/html;charset=gb2312"%>
<% 
//变量声明 
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 rowi;
java.lang.String strPage; 
int i,j,k;  
rowi=0;
String PageSize = (String) session.getValue("pageSize");
//if(PageSize!=null){
intPageSize=Integer.parseInt(PageSize);
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("com.microsoft.jdbc.sqlserver.SQLServerDriver"); 
//设置数据库连接字符串 
strCon ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=sunmoon" ; 
//连接数据库 
sqlCon = java.sql.DriverManager.getConnection(strCon,"sa","sa"); 
//创建SQL语句对象 
sqlStmt = sqlCon.createStatement(); 
//获取记录总数 
 
 String companyName = (String) session.getValue("companyName");
 
if ("全部客户".equals(companyName))
{
    strSQL = "select count(*) from customer"; 
  
}
else  
{
 strSQL = "select count(*) from customer where 客户名称='"+companyName+"'";
 
} 
//strSQL = "select count(*) from loadweight where 收货方='"+company+"' "; 
sqlRst = sqlStmt.executeQuery(strSQL); 
//执行SQL语句并取得结果集 
sqlRst.next(); //记录集刚打开的时候,指针位于第一条记录之前 
intRowCount = sqlRst.getInt(1); 
sqlRst.close(); //关闭结果集 
//记算总页数 
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 
if(intPage>intPageCount) intPage = intPageCount; 
//设置获取数据SQL语句 
//strSQL = "select * from loadweight where 收货方='广州世经'"; 
{
 if ("全部客户".equals(companyName))
  
    {
  strSQL = "select * from customer order by 客户序号"; 
  }
 else
 {
  strSQL = "select * from customer where 客户名称='"+companyName+"' order by 客户序号";
 }
 //strSQL = strSQL+" and 时间 between '2003-3-1' and '2003-4-1' ";
 //out.println(strSQL);
 
}
//执行SQL语句并取得结果集 
sqlRst = sqlStmt.executeQuery(strSQL);
//将记录指针定位到待显示页的第一条记录上 
i = (intPage-1) * intPageSize; 
for(j=0;j<i;j++) sqlRst.next(); %> 
<html> 
<link Language=JavaScript>
  function selectRow(oCurrent)
           {
        oCurrent.style.backgroundColor="CCCCFF";
        for(var i = 0; i < document.all('t1').rows.length;i++)
         {
       if(t1.rows[i] != oCurrent) t1.rows[i].style.backgroundColor="ffffff";
         }
          }
 
 
 function moveto(page)
 {
  form1.action = "/sunmoon/Jsp/inside/customer/customdbqueary.jsp?page=" + page;
  form1.method = "post";
  form1.submit();
 }
   function printPage() { print(document); }
</Script>
<body>
<table width="90%" border="0" align="center">
  <tr>
    <td nowrap>
<div align="center"><strong><font color="#660099" size="4" face="宋体">系统查询结果</font></strong></div></td>
  </tr>
</table>
<p align=center><strong></strong></p> 
<table width=90% border=0 align=center cellpadding=0 cellspacing=0 id=t1>
  <tr> 
    <td width="104" height="16" align=center  nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">编号</font></div></td>
    <td width=60 align=center  nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">客户名称</font></div></td>
    <td width="103" align=center nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">账号</font></div></td>
    <td width="117" align=center nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">税号</font></div></td>
    <td width="117" align=center nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">开户行</font></div></td>
    <td width="86" align=center nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">电话号码</font></div></td>
    <td width="100" align=center nowrap bgcolor="#FFFFCC"> <div align="left"><font color="#0000FF">详单</font></div></td>
  </tr>
  <% 
//显示数据 
i = 0; 
while(i<intPageSize && sqlRst.next()){rowi=rowi+1; %>
    <% if(rowi%2==0) 
 {
    out.print("<tr bgcolor=#CCCCFF onmouseover=selectRow(this)>");
 }
 else
 { 
 //out.print("<tr ">;
 }
 %>
    <td height="18" valign="top" nowrap><%=sqlRst.getString("客户序号")%></td>
    <td valign="top" nowrap><%=sqlRst.getString("客户名称")%></td>
    <td nowrap><%=sqlRst.getString("账号")%></td>
    <td nowrap><%=sqlRst.getString("税号")%></td>
    <td nowrap><%=sqlRst.getString("开户行")%></td>
    <td nowrap><%=sqlRst.getString("电话号码")%></td>
    <%   String customname=sqlRst.getString("客户序号");   
    out.print("<td width=9% nowrap><a href=customsingle.jsp?customer="+customname+">详单</a></td>"); 
 %>
  </tr>
  <% i++; } %>
  <tr bgcolor="#FFCCFF"> 
    <td height="18" colspan=7 align=right> <div align="right"><font color="#0000FF">第<%=intPage%>页 共<%=intPageCount%>页 <a href="customdbqueary.jsp?page=1">首页</a> 
        <%if(intPage>1){%>
        <a href="customdbqueary.jsp?page=<%=intPage-1%>">上一页</a> 
        <%
}
%>
        <%if(intPage<intPageCount){%>
        <a href="customdbqueary.jsp?page=<%=intPage+1%>">下一页</a> 
        <%
}
%>
        <a href="customdbqueary.jsp?page=<%=intPageCount%>">尾页 </a> 
        </font> </div></td>
    <td> </td>
  </tr>
  <tr align="right"> 
    <td height="22" colspan="8"  align="right"  valign="top" nowrap bgcolor="#FFFFFF"> 
      <form name="form1" method="post" action="" >
        <font color="#0000FF">转到第 
        <input type=text name=page size=2 maxlength=3 value=''  页 
        <input class=buttonface type=Submit value='Go'>
        </font> </form></td>
  </tr>
  <tr align="right"> 
    <td height="22" colspan="8" align="right" valign="top"> <input  class=buttonface value="打印" type="button" ></td>
  </tr>
</table>
</body>
</html> 
<% 
//关闭结果集 
sqlRst.close(); 
//关闭SQL语句对象 
sqlStmt.close(); 
//关闭数据库
sqlCon.close();
%>
 
  
 
 
  
