Home > Database > Mysql Tutorial > Oracle分页在Web上的首页

Oracle分页在Web上的首页

WBOY
Release: 2016-06-07 16:44:02
Original
1082 people have browsed it

本例子代码,只讲Oracle分页的常用的一种方法在Web中的使用,不涉及MVC,代码优化等东西,高手请飘过。新手可以参考。

本例子代码,只讲Oracle分页的常用的一种方法在Web中的使用,不涉及MVC,代码优化等东西,高手请飘过。新手可以参考。


    *************************************  Oracle分页的重要代码,,学习自 韩顺平老师的 Java操作Oracle 十二讲  ****************************************

   

   

   
   
   

   

   
   
     
     
   
        //加载驱动
    Class.forName("oracle.jdbc.driver.OracleDriver");
    //建立连接
    Connection conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@192.168.1.5:1521:BJSXT", "scott","tiger");
  //定义结果集   
    ResultSet rs = null;
 
  //从下面开始和SqlServer 一模一样
  Statement sm = conn.createStatement();
 
  //初始化每页的记录条数
  int pageSize = 20;
  String s_PageSize = request.getParameter("pageSize");
    if(s_PageSize!=null && !"".equals(s_PageSize.trim())) {
      pageSize = Integer.parseInt(s_PageSize);
    }

  //总共有多少页,计算得出
  int pageCount = 0;
  //总共有多少条记录,查询得出
  int rowCount = 0;
 
  //当前页
  int currentPage = 1;
  //初始化开始和结束的记录条数
  int start = 1;
  int end = pageSize;
   
    //得到记录总数
    rs = sm.executeQuery("select count(*) from emp");
    while(rs.next()) {
      rowCount = rs.getInt(1);
      if(rowCount%pageSize==0){
      pageCount = rowCount/pageSize;
      } else {
      pageCount = rowCount/pageSize+1;
      }
    }
   
    //当前页码
    String s_CurrentPage = request.getParameter("currentPage");
    if(s_CurrentPage!=null && !"".equals(s_CurrentPage.trim())) {
      currentPage = Integer.parseInt(s_CurrentPage);
      start = (currentPage-1)*pageSize + 1;
      end = currentPage*pageSize;
    }
   
   
    //分页的关键代码
   
    String fenyeSql = "select * from (select a1.*, rownum bieming from (select * from emp) a1 where rownum=" + start;
    out.println(fenyeSql + "
");
   
    rs = sm.executeQuery(fenyeSql);
   
    //##查询所有的员工 rs = sm.executeQuery("select * from emp");
    while(rs.next()){
      out.print("

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

    }
   
    //打印总页数
    for(int i=1; i    out.print("" + i + " ");
    }
   
    rs.close();
    sm.close();
    conn.close();
    %>
   

姓名 薪水
" + rs.getString(2) + "" + rs.getString(6) + "

 

关于Oracle分页查询

探究Oracle分页查询

Oracle分页查询语句的写法

Oracle分页技术详解

本文永久更新链接地址:

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template