Oracle学习笔记(十)——分页显示简单示例

分页显示emp表的用户信息

<%@ page language="java" import="java.util.*,java.sql.*" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%> 




Insert title here


oracle分页案例

> <% //1、加载驱动 Class. forName("oracle.jdbc.driver.OracleDriver"); //2、得到连接 Connection ct=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "***"); //以下部分和sql server部分一模一样 Statement sm=ct.createStatement(); //接受pageNow String s_pageNow=request.getParameter("pageNow"); int pageNow=1; if(s_pageNow!=null){ pageNow=Integer.parseInt(s_pageNow); } //查询总页数 int pageCount=0; int rowCount=0;//总共有几条记录 int pageSize=3;//每页显示几条记录 ResultSet rs=sm.executeQuery("select count(*) from emp"); if(rs.next()){ rowCount=rs.getInt(1); if(rowCount%pageSize==0) pageCount=rowCount/pageSize; else pageCount=rowCount/pageSize+1; } rs=sm.executeQuery( "select * from (select a1.*,rownum rn from (select * from emp) a1 where rownum<="+pageSize*pageNow+") where rn>="+(pageSize*(pageNow-1)+1)); while(rs.next()){ out.println(""); //用户名 out.println( ""); out.println( ""); out.println(""); } //打印总页数 for(int i=1;i<=pageCount;i++){ out.print(" ["+i+"] "); } //关闭打开的资源 rs.close(); sm.close(); ct.close(); %>
用户名薪水
"+rs.getString(2)+""+rs.getString(6)+"


你可能感兴趣的:(数据库)