oracle 分页语句

private static final String QUERYPERPAGESQL = "select * from (select m.*, rownum rn from (select * from music order by id) m where rownum <= ?) where rn > ?";
//该sql语句为每页显示的个数

public List<Music> queryPerPage(int page) {//page为当前处于第几页
List<Music> list = new ArrayList<Music>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
int EndRow = page * CountPerPage;//CountPerPage为每页要显示的个数
int StartRow = (page-1) * CountPerPage;

conn = FactoryOracleDBConn.getOracleDBConn().getConnection();
try {
ps = conn.prepareStatement(this.QUERYPERPAGESQL);
ps.setInt(1, EndRow);
ps.setInt(2, StartRow);
rs = ps.executeQuery();
while(rs.next()){
Music music = new Music();
music.setAuthor(rs.getString("author"));
music.setId(rs.getInt("id"));
music.setName(rs.getString("name"));
music.setSinger(rs.getString("singer"));
list.add(music);
}
} catch (SQLException e) {
e.printStackTrace();
throw new MyRunTimeException("分页显示查询失败", e);
}finally{
FactoryOracleDBConn.getOracleDBConn().colse(conn, ps, rs);
}
return list;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值