iihero@ChinaUnix, ehero.[iihero] 数据库技术的痴迷爱好者. 您可以通过iihero AT qq.com联系到我 以下是我的三本图书: Sybase ASE in Action, Oracle Spatial及OCI高级编程, Java2网络协议内幕
分类: Java
2013-07-17 11:45:13
准备工作:
在Oracle下,建立一张表:
CREATE TABLE mytable(id int, name varchar(32))
/
往表mytable里插入一些值。
testpage.jsp页面程序如下:
< import="java.util.*"%>
< import="java.lang.*"%>
< import="java.io.*"%>
< import="java.sql.*"%>
< import="java.net.*"%>
< contentType="text/html;charset=GBK" %>
<%
String sConn="jdbc:oracle:thin:@host:1521:orcl";
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection(sConn,"user","password");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
//Statement stmtcount=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("select * from mytable");
//String sqlcount="select count(*) from mytable";
//ResultSet rscount=stmtcount.executeQuery(sqlcount);
int pageSize=5; //每页5条
int rowCount=0; //总的记录数
rs.last();
rowCount = rs.getRow();
int pageCount; //总的页数
int currPage = 0; //当前页数
String strPage;
strPage=request.getParameter("page");
if (strPage==null){
currPage=1;
}
else{
currPage=Integer.parseInt(strPage);
if (currPage<1) currPage=1;
}
pageCount=(rowCount+pageSize-1)/pageSize;
if (currPage>pageCount) currPage=pageCount;
int thepage=(currPage-1)*pageSize;
int n=0;
%>
当前为第:<%=currPage%>页
<%
if (currPage>1){
%>
上一页
<%
}
%>
<%
if (currPage
下一页
<%
}
%>
尾 页
"); out.println(rs.getInt(1)+" | "); out.println(rs.getString(2)+" |