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;
}
oracle 分页语句
最新推荐文章于 2024-08-19 08:45:16 发布