jsp +oracle分页问题 主要是在SQL语句上

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


姓 名

班 级

学 号

<%
//定义四个分页会用到的变量
int pageSize=3;
int pageNow=1;//默认显示第一页
int rowCount=0;//该值从数据库中查询
int pageCount=0;//该值是通过pageSize和rowCount
//接受用户希望显示的页数(pageNow)
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
//接收到了pageNow
pageNow=Integer.parseInt(s_pageNow);
}
//查询得到rowCount
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522:shop","cityinfo","Hj63444379");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select count(*) FROM STUDENT ");
if(rs.next()){
rowCount=rs.getInt(1);
}
//计算pageCount
if(rowCount%pageSize==0){
pageCount=rowCount/pageSize;
}else{
pageCount=rowCount/pageSize+1;
}
//查询出需要显示的记录
rs=stmt.executeQuery("SELECT * FROM (SELECT ID,NUM,NAME,ROWNUM rn FROM STUDENT WHERE ROWNUM<=? ORDER BY ID) temp WHERE temp.rn>?");
%>

<%
//while(rs.next()){
out.print("

");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");

while(rs.next()){
String cid=rs.getString(1);
String NUM=rs.getString(2);
out.print("

");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");
out.print("");

}

out.print("

"+"序号"+""+"姓名 "+""+"性别"+""+"状态"+""+"学号"+""+"班级"+""+"身份证"+""+"电话"+""+"邮箱"+""+"操作"+"
"+rs.getString(2)+""+rs.getString(3)+""+rs.getString(4)+""+rs.getString(5)+""+rs.getString(6)+""+rs.getString(7)+""+rs.getString(8)+""+rs.getString(9)+""+rs.getString(10)+"

删除

修改

");
%>

<%
//上一页
if(pageNow!=1){
out.println("上一页");
}
//显示超链接
for(int i=1;i<=pageCount;i++){
out.println("["+i+"]");
}
//下一页
if(pageNow!=pageCount){
out.println("下一页");
}
%>


rs=stmt.executeQuery("SELECT * FROM (SELECT ID,NUM,NAME,ROWNUM rn FROM STUDENT WHERE ROWNUM<=? ORDER BY ID) temp WHERE temp.rn>?");

主要是这句话! 代码都打上去了 这sql是我网上找的稍微改成了自己的但是总觉得不对

我的表名叫STUDENT 主键是ID 然后还有 NUM ,NAME ,SEX ,STATE, STUDENT_ID ,CLASS,ID_CARD ,TEL, MAIL 字段 大神帮个忙被

5个回答

rs=stmt.executeQuery("SELECT ID,NUM,NAME,ROWNUM FROM STUDENT WHERE ROWNUM<=? AND ROWNUM>?ORDER BY ID");
这样就可以了

或者
rs=stmt.executeQuery("SELECT ID,NUM,NAME,ROWNUM FROM STUDENT WHERE ROWNUM between ? AND ?ORDER BY ID");

hjsgkg007
Diamo丶 都没有成功,还是点下面的上一页下一页没有反应的。。。。。。。我把字段都填上了 然后 between那里写的 0 and 3 它也是只能显示三条
4 年多之前 回复

SELECT * FROM (SELECT ID,NUM,NAME FROM STUDENT ORDER BY ID) WHERE ROWNUM<?");

hjsgkg007
Diamo丶 无法翻页啊~
4 年多之前 回复

你把这个SQL直接执行看看能出结果吗

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问