jsp 连接Oracle 分页
2010-11-16 10:21
375 查看
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'liuyan1.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">
-->
<style type="text/css">
th {background-color: gray; padding: 20px;}
</style>
<style type="text/css">
#tab {background-color:#666666}
</style>
</head>
<body>
<marquee bgcolor="green" direction="left"><h1>欢迎您进入留言板系统!</h1> </marquee>
<h3 align="left">欢迎您 游客!<a href="login.jsp">登录</a>|<a href="register.jsp">注册</a></h3>
<%
int pageSize = 2;//每页显示的记录数
int pageCount = 0;//总页数
Connection conn=null;
Statement stmt=null;
String className="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@localhost:1521:zhang";
Class.forName(className);
conn=java.sql.DriverManager.getConnection(url,"system","123");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);//注意 加粗这一句是必须的加上的
ResultSet rs=stmt.executeQuery("select * from thread");
if(rs.next())
{
rs.last(); //让游标到表中的最后一行
int rowCount = rs.getRow(); //获取记录总数.
pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize ) : (rowCount / pageSize +1);
int showPage = 1;//当前页
//取得用户所指定的页
String goToPage = request.getParameter("showPage");
if (goToPage == null){
goToPage = "1";
}
//转换成整形
showPage = Integer.parseInt(goToPage);
//当前页小于等于第一页则按第一页算 如果 当前页大于等于总页数则为最后页
if(showPage <=1){
showPage = 1;
}
else if(showPage >= pageCount){
showPage = pageCount;
}
//游标的位置 (当前页 - 1) * 页面大小 + 1
int posion = (showPage -1 ) * pageSize + 1;
//设置游标的位置
rs.absolute(posion);
%>
<table border="1" id="tab">
<tr>
<td width="160">标题</td>
<td width="160">作者</td>
<td width="160">发表时间</td>
</tr>
</table>
<%
int i =0;
//循环显示表中的数据 pageSize(每页所显示的记录)
//rs.isAfterLast() 游标是否在最后一行之后说明后面已经没记录
while(i<pageSize && !rs.isAfterLast()){
%>
<table border="1">
<col width="160px"/><col width="160px"/><col width="160px"/><col width="160px"/>
<tr>
<td><a href="readliuyan.jsp?name=<%=rs.getString("tname") %>"><%=rs.getString("tname")%></a></td>
<td><%=rs.getString("uname")%></td>
<td><%=rs.getString("time")%></td>
</tr>
<%rs.next();i++;}%>
</table>
<form action="" method="get">
<table border="1">
<tr>
<td>当前第<%=showPage%>页</td>
<td>共<%=pageCount%>页</td>
<td>
<a href="liuyan1.jsp?showPage=1">首页</a>
<a href="liuyan1.jsp?showPage=<%=showPage-1%>">上一页</a>
<a href="liuyan1.jsp?showPage=<%=showPage+1%>">下一页</a>
<a href="liuyan1.jsp?showPage=<%=pageCount%>">尾页</a>
</td>
<td> 共<%=rowCount%>条记录 </td>
<td>转到
<input type="text" name="showPage" size="4"/>
<input type="submit" name="go" value="提交"/>
</td>
</tr>
</table>
</form>
<%
}
%>
</body>
</html>
<%@ page import="java.sql.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'liuyan1.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">
-->
<style type="text/css">
th {background-color: gray; padding: 20px;}
</style>
<style type="text/css">
#tab {background-color:#666666}
</style>
</head>
<body>
<marquee bgcolor="green" direction="left"><h1>欢迎您进入留言板系统!</h1> </marquee>
<h3 align="left">欢迎您 游客!<a href="login.jsp">登录</a>|<a href="register.jsp">注册</a></h3>
<%
int pageSize = 2;//每页显示的记录数
int pageCount = 0;//总页数
Connection conn=null;
Statement stmt=null;
String className="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@localhost:1521:zhang";
Class.forName(className);
conn=java.sql.DriverManager.getConnection(url,"system","123");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);//注意 加粗这一句是必须的加上的
ResultSet rs=stmt.executeQuery("select * from thread");
if(rs.next())
{
rs.last(); //让游标到表中的最后一行
int rowCount = rs.getRow(); //获取记录总数.
pageCount = (rowCount % pageSize == 0) ? (rowCount / pageSize ) : (rowCount / pageSize +1);
int showPage = 1;//当前页
//取得用户所指定的页
String goToPage = request.getParameter("showPage");
if (goToPage == null){
goToPage = "1";
}
//转换成整形
showPage = Integer.parseInt(goToPage);
//当前页小于等于第一页则按第一页算 如果 当前页大于等于总页数则为最后页
if(showPage <=1){
showPage = 1;
}
else if(showPage >= pageCount){
showPage = pageCount;
}
//游标的位置 (当前页 - 1) * 页面大小 + 1
int posion = (showPage -1 ) * pageSize + 1;
//设置游标的位置
rs.absolute(posion);
%>
<table border="1" id="tab">
<tr>
<td width="160">标题</td>
<td width="160">作者</td>
<td width="160">发表时间</td>
</tr>
</table>
<%
int i =0;
//循环显示表中的数据 pageSize(每页所显示的记录)
//rs.isAfterLast() 游标是否在最后一行之后说明后面已经没记录
while(i<pageSize && !rs.isAfterLast()){
%>
<table border="1">
<col width="160px"/><col width="160px"/><col width="160px"/><col width="160px"/>
<tr>
<td><a href="readliuyan.jsp?name=<%=rs.getString("tname") %>"><%=rs.getString("tname")%></a></td>
<td><%=rs.getString("uname")%></td>
<td><%=rs.getString("time")%></td>
</tr>
<%rs.next();i++;}%>
</table>
<form action="" method="get">
<table border="1">
<tr>
<td>当前第<%=showPage%>页</td>
<td>共<%=pageCount%>页</td>
<td>
<a href="liuyan1.jsp?showPage=1">首页</a>
<a href="liuyan1.jsp?showPage=<%=showPage-1%>">上一页</a>
<a href="liuyan1.jsp?showPage=<%=showPage+1%>">下一页</a>
<a href="liuyan1.jsp?showPage=<%=pageCount%>">尾页</a>
</td>
<td> 共<%=rowCount%>条记录 </td>
<td>转到
<input type="text" name="showPage" size="4"/>
<input type="submit" name="go" value="提交"/>
</td>
</tr>
</table>
</form>
<%
}
%>
</body>
</html>
相关文章推荐
- jsp连接oracle实现分页功能的源代码
- 分页显示问题的解决方法(jsp,sqlserver,mysql,oracle)
- jsp连接Oracle错误:ocijdbc8.dll already loaded 解决方法
- Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
- jsp连接oracle实例
- jsp+oracle实现简单的分页
- Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台) 选择自 dazern 的 Blog
- 详细的jsp分页(oracle+jsp+apache)
- 分页显示问题的解决方法(jsp,sqlserver,mysql,oracle)
- JSP连接数据库(oracle,sqlserver,DB2,MySQL等)
- JSP 连接各类数据库大全(Oracle,MSSQL,DB2,Informix,SyBASE,MYSQL,PostgreSQL)
- JSP连接数据库实现分页显示
- 在用ORACLE数据库和JSP连接时要注意的一些问题精粹
- oracle建表权限问题和JSP连接oracle数据库基本操作
- jsp + oracle 排序分页 高效sql语句
- jsp连接数据库分页显示
- jsp连接oracle
- 连接Oracle的JSP测试程序
- JSP连接Oracle
- 转:JSP 分页显示数据 (Oracle)