package com.test;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class page {
public static void main(String[] args) {
testCon tc = new testCon();
int pageSize = 4;//每页显示的数据量
int pageNow = 1;//当前页码
Connection con = tc.getCon();//获取jdbc连接
String sql = "select * from (select rownum r,emp.* from emp where rownum<=?) t where t.r>?";//此处的查询语句和其他数据库查询语句不一样
try {
PreparedStatement pst = con.prepareStatement(sql);
pst.setInt(1, pageSize*pageNow);
pst.setInt(2, pageSize*(pageNow-1));
ResultSet rs = pst.executeQuery();
int count = 0;
while(rs.next()) {
count++;
int eno = rs.getInt("empno");
String ename = rs.getString("ename");
String job = rs.getString("job");
double sal = rs.getDouble("sal");
System.out.println(eno+"\t"+ename+"\t"+job+"\t"+sal);
}
System.out.println("当前页"+pageNow+"\t"+"每页"+count+"条数据");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Oracle-控制台版分页
最新推荐文章于 2024-07-22 15:12:37 发布