jsp oracle分页与sqlserver分页

先来个sqlserver分页
数据库很简单就一张表
表字段有:
id,主键,自动增长
name 组名

直接贴代码;


<%@ page language="java" import="java.sql.*,java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String pageNowStr=request.getParameter("pageNow"); //当前是第几页
int pageNow=1;
if(pageNowStr!=null){
pageNow=Integer.valueOf(pageNowStr);
}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<table border="1">
<%
Connection conn=null;
PreparedStatement pst=null;
ResultSet result=null;
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DataBaseName=Spring_dataBase","sa","123456");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int pageSize=3; //每页多少条记录
int rowCount=0; //总共有多少条记录
int pageCount=0; //总共有多少页记录

String queryPageCount="select count(*) from Group_tbl";
try {
pst=conn.prepareStatement(queryPageCount);
result=pst.executeQuery();
while(result.next()){
rowCount=result.getInt(1); //获取页数
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}

System.out.print("pageCount"+pageCount);
String sql="select top "+pageSize+" * from Group_tbl where id not in(select top "+pageSize*(pageNow-1)+"id from Group_tbl)";
try {
pst=conn.prepareStatement(sql);
result=pst.executeQuery();
while(result.next()){
out.print("<tr><td>"+result.getString("id")+"</td><td>"+ result.getString("name")+"</td></tr>");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
result.close();
pst.close();
conn.close();
}
%>
</table>
<%
if(pageNow!=1){
out.print("<a href=sqlserver.jsp?pageNow="+(pageNow-1)+">上一页</a>   ");
}
for(int i=pageNow;i<pageNow+3;i++){
if(i<=pageCount) //使其不超过总页数
out.print("<a href=sqlserver.jsp?pageNow="+i+">"+i+"</a>   ");

}
if(pageNow<pageCount)
out.print("<a href=sqlserver.jsp?pageNow="+(pageNow+1)+">下一页</a>");
%>


<br>
</body>
</html>



效果如下;

[img]http://dl.iteye.com/upload/attachment/577624/649ccfcd-f6f8-36da-ac86-acacf7994277.bmp[/img]


----------------------------------------------------------------------
再来个oracle分页
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值