JDBC 连接 实现分页(oracle sqlservlet ...)


<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<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="jdbc page test">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<%
String driver = "oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@127.0.0.1:1521:orcle";
String username = "system";
String password = "password";

Class.forName(driver);
Connection conn = DriverManager.getConnection(url,username,password);
Statement stm = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmcount = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

ResultSet rs = null;
ResultSet rscount = null;
String selectSql = "select * from zmail where name like '%name%' order by id desc ";
String countSql = "select count(*) from zmail where name like '%name%' ";
rs = stm.executeQuery(selectSql);
rscount = stmcount .executeQuery(countSql);

int pageSize = 10;//每页显示条数
int rowCount = 0;
while(rscount.next())
rowCount = rscount.getInt(1 );
int pageCount;
int curPage;
String strPage = request.getParameter("page");
curPage = strPage == null ? 1 : Integer.parseInt(strPage) ;
curPage = curPage <1 ? 1 :curPage;

pageCount = (rowCount + pageSize -1)/pageSize;

curPage = curPage > pageCount ? pageCount : curPage;

int thePage = (curPage - 1) * pageSize;
int n = 0;
rs.absolute(thePage + 1 );
%>

<table width="1010" height="736" border="0" align="center"
cellpadding="0" cellspacing="0" background="images/jzxx_bg.jpg"
bgcolor="#FFFFFF">
<tr>
<td height="100" style="padding-left: 100px;">
<img src="images/jzxx_logo.gif">
</td>
</tr>
<tr>
<td valign="top">
<table width="80%" border="0" align="center">
<tr>
<td width="140" height="180" align="center">
<img src="images/jzxx_photo.jpg">
</td>
<td>
<img src="images/jzxx_ms.gif">
</td>
</tr>
</table>
<table width="80%" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td width="84">
<a href="jZTJiao.html"><img src="images/jzxx_menu4.gif"
width="84" height="28" border="0">
</a>
</td>
<td width="85">
<a href="/ywzx/fenyeList.do?method=JzxxList&&bm=1&&pageno=1"><img
src="images/jzxx_menu5.gif" width="85" height="28" border="0">
</a>
</td>
<td background="images/jzxx_menu3.gif">

<table width="60%" border="0" cellpadding="0" cellspacing="0">
<form id="form" name="form" method="post" action="fenyeList.do" >
<input type="hidden" name="method" id="method" value="souSuo" />
<input type="hidden" name="pageno" id="pageno" value="1" />
<input type="hidden" name="biaoming" id="biaoming" value="1" />
<tr>
<td width="60" align="center">
搜索:
</td>
<td width="145">
<input type="text" id="searchword" name="searchword"
onClick="document.form.searchword.value=''" value="请输入关键字"
style="border: 1px solid #C5C5C5; height: 21px; width: 145px; color: #999999; padding: 3 0 0 4;">
</td>
<td>
<input type="image" src="images/list_simg.gif"
onClick="submitsearch()">
</td>
</tr>

</table>
</td>
</tr>
</table>
<br>

<TABLE width="70%" border=0 align="center" cellpadding=4
cellspacing=1 bgcolor="#F6E2AD">

<%
while(n < pageSize && !rs.isAfterLast()){
%>
<TR>
<TD width="50" align="right" bgcolor="#FBF1D9">
姓名:
</TD>
<TD height="40" bgcolor="#FFFFFF">
<%= rs.getString("name")%>
</TD>
</TR>
<tr>
<TD align="right" bgcolor="#FBF1D9">
内容:
</TD>
<TD height="40" colspan="3" bgcolor="#FFFFFF">
<%=rs.getString("neirong")%>
</TD>
</TR>
<TR>
<TD align="right" bgcolor="#FBF1D9">
回复:
</TD>
<TD style="text-indent: 2em" height="40" colspan="3"
bgcolor="#FFFFFF">
<%=rs.getString("huifu")%>
</TD>
</TR>
<%
rs.next();
n++;
}
%>

</TABLE>

<table width="70%" border="0" align="center" cellpadding="10"
cellspacing="0">
<tr>
<td>
 
</td>
<td align="right">
第<%=curPage%>页 共<%=pageCount%>页 共<%=rowCount%>条
<%if(curPage>1){%><a href="listJzmail.jsp">首页</a><%}%>
<%if(curPage>1){%><a href="listJzmail.jsp?page=<%=curPage-1%>">上一页</a><%}%>
<%if(curPage<pageCount){%><a href="listJzmail.jsp?page=<%=curPage+1%>">下一页</a><%}%>
<%if(pageCount>1){%><a href="listJzmail.jsp?page=<%=pageCount%>">尾页</a><%}%>
</td>
</tr>
</table>
</td>

</tr>
</table>



</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值