hjsgkg007
Diamo丶
采纳率0%
2015-08-27 08:12 阅读 1.6k

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条回答 默认 最新

  • jiajia333666 jiajia333666 2015-08-27 12:55

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

    点赞 1 评论 复制链接分享
  • jiajia333666 jiajia333666 2015-08-27 13:03

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

    点赞 1 评论 复制链接分享
  • strutce 丵鹰 2015-08-27 13:15

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

    点赞 1 评论 复制链接分享
  • u013147600 六月心悸 2015-08-27 13:40
    点赞 评论 复制链接分享
  • yuke198907 yuke198907 2015-08-28 00:36

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

    点赞 评论 复制链接分享

相关推荐