`

自己写的历史查询(mysql)加分页

阅读更多
//样式和数据库的列名都是对照实际的,所以不能通用,不过可以看出怎么做了

<%@ page language="java" pageEncoding="UTF-8"%>

<%@page import="java.sql.*"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
   
<style>
body{font-size:12px;letter-spacing:1px;}
input{vertical-align:text-bottom;}
.tbDiv{margin:0 auto;width:775px}
.tb{border:1px solid #88DAFD;line-height:24px;width:100%}
.tb tr td{border-bottom:1px solid #ccc;text-align:center}
.tbHead{background:#E0F4FF;color:#0B9CD9}

.searchItem{border:1px solid #88DAFD}
.searchItem .tbHead{line-height:24px;border-bottom:1px solid #88DAFD}
.searchContainer{padding:10px;}
.searchInput{border:1px solid #4EC6F9}
.even{background:#F9F9F9}

.tb2{border:1px solid #88DAFD;line-height:24px;width:410px;text-align:left}
.tb2 tr td{border-right:1px solid #ccc;border-bottom:1px solid #ccc;text-align:center}
.tb2 .tbHead{text-align:left}

.mbm{background:url(../images/siOrder/ico.gif) -515px -40px;height:14px;width:12px;display:block;}
.mbm1{background:url(ico.gif) -563px -40px;height:14px;width:12px;display:block;}
.mbm2{background:url(ico.gif) -587px -40px;height:14px;width:12px;display:block;}
.mbm3{background:url(ico.gif) -587px -40px;height:14px;width:12px;display:block;}
.mbm4{background:url(ico.gif) -1786px -2px;height:24px;width:24px;display:block;}
.mbm6{background:url(../images/siOrder/ico.gif) -2117px -10px;height:12px;width:15px;display:block;}
.mbm7{background:url(../images/siOrder/ico.gif) -2144px -10px;height:12px;width:12px;display:block;}

.jiantou {/*display:inline-block;*/display:none;border:0 solid #fff;border-width:3px 3px 0;border-color:#090 #fff;width:0;height:0;overflow:hidden;cursor: pointer;color:#0B9CD9}
</style>
  </head>
 
  <body>

<table id="tbView" class="tb" cellpadding="0" cellspacing="0">
<tr class="tbHead">
<!-- <td width="6%">ID</td> -->
  <td width="12%">订单号</td>
  <td width="18%">旅客名</td>
  <td width="15%">下订时间</td>
  <td width="9%">订购/退(张)</td>
  <td width="10%">金额(元)</td>
<td width="5%"><span onclick="">类型</span><span class="jiantou"></span></td>
  <td width="10%"><span onclick="">支付方式</span><span class="jiantou" onclick=""></span></td>
  <!-- <td width="3%">新单</td> -->
  <td width="6%"><span onclick="">订票<br/>状态</span><span class="jiantou" onclick=""></span></td>
  <td width="5%"><span onclick="">申请<br/>退票</span><span class="jiantou" onclick=""></span></td>
  <td width="10%">订单<br/>备注</td>
  </tr>
 
 
  <%
 

  Connection conn;
  PreparedStatement stat;
  String url="jdbc:mysql://localhost:3306/xinnuo";
  String user="root";
  String password="root";
 

  Class.forName("com.mysql.jdbc.Driver");
 
 
  conn=DriverManager.getConnection(url,user,password);
  String s="select * from si_order_main_history";
     stat=conn.prepareStatement(s);
ResultSet result=stat.executeQuery();

 
int intPageSize; //一页显示的记录数 
int intRowCount; //记录总数 
int intPageCount; //总页数 
int intPage; //待显示页码 
String strPage;  //传递过来的页码
int i; 
//设置一页显示的记录数 
intPageSize = 20; 

result.last(); 
intRowCount = result.getRow(); 
//记算总页数 
intPageCount = (intRowCount+intPageSize-1) / intPageSize;

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){ 
//表明在QueryString中没有page这一个参数,此时显示第一页数据 
intPage = 1; 
} else{ 
//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage< 1) intPage = 1; 

if(intPage>intPageCount)  intPage = intPageCount;
if(intPageCount>0) 

//将记录指针定位到待显示页的第一条记录上 
result.absolute((intPage-1) * intPageSize + 1); 
//显示数据 
}
i = 0;



while(i< intPageSize && !result.isAfterLast()){ 
out.println("<tr>");
 
  out.println("<td>"+result.getString("MainOrder_ID")+"</td>");
  out.println("<td>"+result.getString("MainOrder_UserName")+"</td>");
  out.println("<td>"+result.getString("MainOrder_Time")+"</td>");
  out.println("<td>"+result.getString("MainOrder_BuyNums")+"</td>");
  out.println("<td>"+result.getString("MainOrder_Cost")+"</td>");
  out.println("<td>"+result.getString("OrderType")+"</td>");
  out.println("<td>"+result.getString("MainOrder_PayType")+"</td>");
  out.println("<td>"+result.getString("MainOrder_IsCheck")+"</td>");
  out.println("<td>"+result.getString("MainOrder_IsRefund")+"</td>");
  out.println("<td>"+result.getString("MainOrder_Marks")+"</td>");
 
  out.println("</tr>");

result.next(); 
i++;

  }


 
 
%> 
</table> 
 

第<%=intPage%>页 共<%=intPageCount%>页 
<%if(intPage<intPageCount){%>
<a href="fenye.jsp?page=<%=intPage+1%>"> 下一页 </a>
<%}%>
  <%if(intPage>1){%>   <a href="fenye.jsp?page=<%=intPage-1 %>">  上一页 </a>  <%}%>
 

  <a href="fenye.jsp?page=2">  转到第一页 </a> 
       <a href="fenye.jsp?page=<%=intPageCount%>">  转到第后一页 </a> 

  </body>
</html>




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics