<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%!
public static final String DBDRIVER="oracle.jdbc.driver.OracleDriver";
public static final String DBURL="jdbc:oracle:thin:@localhost:1521:zxy";
public static final String DBUSER="scott";
public static final String DBPASS="admin";
%>
<%
//分页需要的变量
int currentPage=1;//当前页,默认第一页
int lineSize=10;//每页显示的记录数
int allRecords=0;//总记录数,需查询后计算出来
int pageSize=0;//总页数,需要计算
try{
currentPage = Integer.parseInt(request.getParameter("cp"));
}catch(Exception e){
}
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
String sql="SELECT empno,ename,job,hiredate,sal,comm FROM emp";
ResultSet rs=null;
int empno=0;
String ename=null;
String job=null;
java.util.Date hiredate =null;
float sal=0.0f;
float comm=0.0f;
%>
<%
try{
//加载驱动程序
Class.forName(DBDRIVER);
//连接数据库
conn=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
//执行查询操作
pstmt=conn.prepareStatement(sql);
//保存查询结果
rs=pstmt.executeQuery();
while(rs.next()){
allRecords++;
}
try{
rs.close();
pstmt.close();
pageSize=(allRecords+lineSize-1)/lineSize;//计算出总页数
}catch(Exception e){}
}catch(Exception e){}
%>
<center>
<h2>雇员信息</h2>
<script language="javaScript">
function go(c){
document.getElementById("cp").value = c ;
document.spform.submit() ; // 提交表单
}
</script>
<form action="SplitPage_True.jsp" name="spform" method="post">
<input type="button" value="首页" onClick="go(1)" <%=currentPage==1?"disabled":""%>>
<input type="button" value="上一页" onClick="go(<%=currentPage-1%>)"<%=currentPage==1?"disabled":""%>>
<input type="button" value="下一页" onClick="go(<%=currentPage+1%>)"<%=currentPage==pageSize?"disabled":""%>>
<input type="button" value="尾页" onClick="go(<%=pageSize%>)"<%=currentPage==pageSize?"disabled":""%>>
<input type="hidden" name="cp" value="">
</form>
<table border="1">
<tr>
<th>雇员编号</th>
<th>雇员姓名</th>
<th>工作</th>
<th>雇佣日期</th>
<th>工资</th>
<th>奖金</th>
</tr>
<%
//循环输出表信息
sql="SELECT empno,ename,job,hiredate,sal,comm FROM (select empno,ename,job,hiredate,sal,comm,ROWNUM rn FROM emp WHERE ROWNUM<="+currentPage*lineSize+") temp WHERE temp.rn>"+(currentPage-1)*lineSize;
pstmt=conn.prepareStatement(sql);
rs=pstmt.executeQuery();
while(rs.next()){
empno=rs.getInt(1);
ename=rs.getString(2);
job=rs.getString(3);
hiredate=rs.getDate(4);
sal=rs.getFloat(5);
comm=rs.getFloat(6);
%>
<tr>
<td><%=empno%></td>
<td><%=ename%></td>
<td><%=job%></td>
<td><%=hiredate%></td>
<td><%=sal%></td>
<td><%=comm%></td>
</tr>
<%
}
%>
</table>
</center>
<%
try{
conn.close();
}catch(Exception e){}
%>
</body>
</html>可以连接到数据库,但是分页实现不了,帮个忙,谢谢,我弄了很久都没弄好,表是oracle里的emp表